Here are the commands you’ll actually use.

The modes

Vim has four modes, and this is the foundation of everything:

  • Normal mode: the default mode. You navigate and run commands. You don’t write.
  • Insert mode: you type text, like in any other editor. Enter it with i, exit with Esc.
  • Visual mode: you select text (with v).
  • Command mode: you type commands after : at the bottom of the screen.

If you’re lost, press Esc to go back to normal mode. Always.

Moving around

In normal mode:

  • h j k l: left, down, up, right (yes, not the arrow keys, although they also work)
  • w: next word
  • b: previous word
  • 0: start of the line
  • $: end of the line
  • gg: start of the file
  • G: end of the file
  • :10: go to line 10

Writing text

To switch to insert mode:

  • i: insert before the cursor
  • a: insert after the cursor
  • o: new line below
  • O: new line above

Esc to return to normal mode.

Copy, cut, paste

In normal mode:

  • yy: copy the line
  • dd: cut the line
  • p: paste after the cursor
  • P: paste before

In visual mode (with an active selection):

  • y: copy the selection
  • d: cut the selection

Search and replace

  • /pattern: search forward
  • ?pattern: search backward
  • n: next occurrence
  • N: previous occurrence
  • :%s/old/new/g: replace everywhere in the file
  • :s/old/new/g: replace on the current line

Undo

  • u: undo
  • Ctrl + r: redo

Multiple files

  • :e file: open a file
  • :sp file: open in a horizontal split
  • :vsp file: open in a vertical split
  • Ctrl + w then h/j/k/l: switch between windows

Advanced commands

These change your life once you know them:

  • .: repeat the last action. Probably the most useful command in Vim.
  • ci": clear the content between quotes and switch to insert. Also works with ci(, ci{, ci[.
  • da(: delete the parentheses and their content.
  • >G: indent from the current line to the end of the file.
  • =G: re-indent to the end of the file.

Macros

For repetitive tasks:

  1. qa: start recording into register “a”
  2. Do your actions
  3. q: stop recording
  4. @a: replay the macro
  5. 10@a: replay the macro 10 times

.vimrc

The ~/.vimrc file holds your configuration. A reasonable minimum:

set number          " line numbers
set autoindent      " auto indentation
set tabstop=4       " tab width
set expandtab       " spaces instead of tabs
syntax on           " syntax highlighting

That’s a starting point. Vim config is a rabbit hole: you can spend hours on it. Start simple. To put Vim through its paces on a short front-end project, try a spinning 3D cube in CSS.