Vim vs Nano: Key Differences and Essential Commands for Both Editors

Vim vs Nano: Key Differences and Essential Commands for Both Editors

·

3 min read

Vim Editor

Vim (short for "Vi improved") is a powerful, highly configurable, and efficient text editor used primarily for editing code and text in a terminal or command-line environment.

➤ It's an enhanced/Advanced version of the original Vi editor, which is one of the oldest and most widely used text editors on Linux Systems.

Three Modes of Vim editor:

  • Normal mode: Used for navigation and manipulating text (e.g., cut, copy, paste).

  • Insert mode: Used for typing and editing text.

  • Command-line mode: Used for executing commands like saving, quitting, or searching.

Commands:

  • vim file_name → If file is not present it creates a file and opens in vim editor

  • i → insert mode

To exit the vim editor

  • Type in (esc : wq) → to save and exit

  • esc:q! → to quit without saving

  • shift+G → to go to last line in a file

  • gg → to go to top line in a file

  • esc → to come out of modes

  • /search word → to search any word in the file

    • followed by n → to go to next word that matches (top to bottom)

    • followed by ? → (bottom to up)

    • followed by * → to search automatically by just pointing cursor to that word

  • :%s/word1/replace word→ to replace a word with another word

  • u → to undo

  • shift+r → to redo

  • o → to go to next line in the file

  • shift+o → to go up

  • shift + i → to go to starting line

  • shift + a → to go to last line

  • x → to delete a character

  • r → replacement mode

  • dd → to delete a line

  • :e! → to undo everything

  • dd & p → to cut and paste

  • shift+p → to paste

  • shift+v → to select one whole line

  • v → visual mode

  • y → to copy the selected line

  • :set nu → to assign numbers to the lines

  • :set nonu → to remove numbers

  • :syntax on/off → to on and off the color scheme

  • The syntax is on means the color scheme

  • Now the syntax is off

  • vim -o file1 file2 → two files will open up and down

    → Two files one is txt file and second one is script file

  • vim -d file1 file2 → to the diff between two files

    It basically shows the difference in both the files

Nano Editor

Nano is a simple, user-friendly text editor for Unix-like operating systems. It runs in the terminal and is designed for users who want an easy-to-use editor without the complexity and learning curve of editors like Vim.

➤ It’s widely available on Linux and macOS systems, and often the default terminal-based text editor.

Commands:

  • Move the cursor one character to the right:
    Press the (right arrow key).

  • Move the cursor one character to the left:
    Press the (left arrow key).

  • Move the cursor one line up:
    Press the (up arrow key).

  • Move the cursor one line down:
    Press the (down arrow key).

  • Move to the beginning of the current line:
    Press Ctrl + A.

  • Move to the end of the current line:
    Press Ctrl + E.

  • Move to the top of the document:
    Press Ctrl + Y.

  • Move to the bottom of the document:
    Press Ctrl + V.

  • Move to a specific line number:
    Press Ctrl + _, type the line number, and press Enter.

  • Search for a word or phrase:
    Press Ctrl + W, then type the word/phrase you’re looking for and press Enter.