Vim Essentials: A Beginner's Guide to Text Editing and Productivity

Vim Essentials: A Beginner's Guide to Text Editing and Productivity

VIM stands for vi (improved).

To install Vim open the terminal and run the command.

sudo apt update
sudo apt install vim

or you can download it from the Vim website's official Vim installer.

Open Terminal just type vim.

it will look like this

It will pop up on the terminal like this.

before going on let's learn how to save and exit Vim.

Saving and Exiting

Press esc to make sure you are in Normal mode.

Quit (without Saving):

:q: is used to quit Vim without saving changes.

If you made any changes and tried to quit. Vim will display an error.

Save:

:w: is used to write or save changes without quitting vim. Allows you to continue editing.

Save and Exit:

:wq or :x is used to save changes to Files and quit Vim.

In Vim, :x and :w are both commands related to saving changes to a file, but they have different behaviors.

  • if the file is not saved, :x is the same as :wq . it will save changes before quitting.

  • if there are no unsaved changes, :x is equivalent to :q .

Force Quit (discard changes):

:q! : Quit Vim without saving any changes.

Navigation

Now you may notice the mouse is nowhere used to navigate in vim.

  • h or the left arrow key - move left one character.

  • l or the right arrow key - move the right one character.

  • j or the down arrow key - move the down one line.

  • k or the up arrow key - move the up one line.

Text Editing

Insertion

Press i to insert text.

at the bottom of the terminal, you will see -- INSERT -- . it indicates you are in insert mode right now. you can exit Insert mode by pressing Esc.

Deletion

  • just press x to delete characters under the cursor and also to cut the selected text and just paste by pressing p. Make sure you are in normal mode.

  • dd use it to delete the entire line.

Appending

  • By pressing A You will be moved to the end of the line no matter where are you in the line.

  • O insert the text in the Previous line.

o insert the text in the next line.

after completing you can back to Normal mode.

Bonus Tip:

  • yy - copy the entire line.

  • y - copy whatever you selected.

  • u - undo.

  • Ctrl + r - for redo your last action.

You can do hands-on practice with these basic commands and check the built-in tutorial by just typing vimtutor in terminal.