← Back to all blog posts
Jump to article
Linux article

Vim Cheat Sheet (and How to Actually Exit Vim)

Modes, moving, editing, search-and-replace, saving and quitting - the commands you need.

Vim Cheat Sheet (and How to Actually Exit Vim)

Vim is everywhere on Linux servers, and it is modal - keys do different things depending on the mode. Here is the cheat sheet, including the famous one. Try every command in the free online Linux terminal, and learn it properly in the Vim lesson.

How to exit Vim

  • :q - quit (if nothing changed)
  • :q! - quit and discard changes
  • :wq or :x - save and quit
  • ZZ - save and quit (from normal mode)

Press Esc first if a command does not seem to work - you are probably in the wrong mode.

Modes

  • Normal - where you move and run commands (press Esc to get here)
  • Insert - typing text (i, a, o)
  • Command-line - the : commands above

Moving

  • h j k l - left, down, up, right
  • w / b - next / previous word
  • 0 / $ - start / end of line
  • gg / G - top / bottom of file
  • :42 - jump to line 42

Editing

  • x - delete a character; dd - delete a line; dw - delete a word
  • yy - copy a line; p - paste
  • u - undo; Ctrl+r - redo
  • r - replace one character; cw - change a word

Search and replace

  • /word - search forwards; n / N - next / previous match
  • :%s/old/new/g - replace every occurrence in the file
  • :%s/old/new/gc - same, but confirm each one

Build the muscle memory

Vim only sticks with practice. Open the online Linux terminal and edit a real file, or work through the free Learn Linux course.

HOME LABS COMMUNITY DASHBOARD