This guide helps anyone open a file in Vim, edit it, save, and exit.

Know how to exit Vim

Modes

Vim has 4 main modes:

  • Normal – move, delete, undo, redo
  • Insert – type text
  • Visual – select text
  • Command – type : commands like save or quit

checkout Commands

Basic Commands

  • To edit a file, go to insert mode by pressing i or a, then start typing.
  • Once done typing, press Esc to go back to normal mode.
  • To save the file, type :w (: goes to command mode, w means write).
  • To quit, type :q (q means quit).
  • To save and quit at the same time, type :wq.
  • To force quit without saving, type :q!.
  • To go back to normal mode from any mode, just press Esc. It always works.
  • To select text, press v for letters or V for the whole line.
  • To undo, press u (like Ctrl+Z), and to redo, press Ctrl + r.

Vim Commands Table (Logical Order)

KeymapModeWhat it does
iInsertStart typing
aInsertStart typing after text
EscAnyBack to normal mode
hNormalMove left
jNormalMove down
kNormalMove up
lNormalMove right
vNormalSelect letters
VNormalSelect whole line
dNormalDelete selection
dwNormalDelete a word
ggNormalGo to top of file
{NormalJump backward paragraph
}NormalJump forward paragraph
uNormalUndo last change
Ctrl + rNormalRedo change
:wCommandSave file
:qCommandQuit
:wqCommandSave and quit
:q!CommandQuit without saving

Fast Navigation


Horizontal Motion


The Speed choice