Skip to main content

How to use vim

Installation

Example of installation on Ubuntu.

apt-get update
apt-get install vim

Open a file

If your user does not have sufficient permissions, you will need to prefix the command with `sudo`.

sudo vim file.txt

Modes in vim

Once you’re in Vim, you’ll be in normal mode, which allows you to view and search through the file.

image.png

To edit the file, you need to be in insert mode.

  • Use the 'i' key, to enable it.
  • Use the Escape key to exit.

image.png

Finally, to use commands, there is command mode, which is activated by pressing the Escape key.

  • Use the ':' key, to enable it.
  • Use the Enter key to apply it.

image.png

Commands

From normal mode (press Esc just in case), press ':' key to move to the bottom of the screen and use one of these commands, followed by Enter.

CommandAction
:wSave (write) without exiting.
:qExit (quit). Vim will not let you exit if there are unsaved changes.
:wqSave and exit.
:q!Forcefully exit without saving changes.

Navigation

From normal mode.

CommandAction
arrow left or hLeft
arrow down or jDown
arrow up or kUp
arrow right or lRight

Quick edit

From normal mode.

CommandAction
xDeletes the character under the cursor (like the Delete key).
ddRemove and cut the full line
uUndo
ctrl + rRedo