Skip to content
Franklin Wise edited this page May 13, 2015 · 8 revisions

VIM Cheat Sheet

Too exit out of VIM. Hit escape (one or more times) then type :q

To save. Hit escape (one or more times) then type :w

THREE MODES!!!

Command Mode - hit escape one or more times and you'll get here

Special Commands - typing the following characters enable some special command modes

  • : - execute a vi command, it's like the tool bar for vi. so to save you type :w (write) and to quit ❓
  • / - find - odd regex syntax for vi unless you type /\v
  • %s/ - substitute (find replace) %s/findexp/replacexp/gI where g is the whole doc and capital I is case sensitive and lower i is case insensitive
  • ! - run whatever follows on the shell

Edit Mode - hit one of the edit keys in command mode and you get here. once you are in edit mode, it's just like notepad until you hit the escape key.

  • i - insert
  • o - open
  • a - append

Visual Mode - hit v and then move around and it'll select text like you would with click and drag on the mouse. Whatever is selected can be copied, replaced, cut, deleted by typing the corresponding 'command' key (i.e. x for cut)

Moving Around (in command mode)

one letter at a time:

  • j - down

  • k - up

  • h - left

  • k - right

one word at a time:

  • w - word forward
  • e - end of word forward
  • b - back a word

line:

  • $ - end of line (just like regex)
  • ^ - first non-white character (think regex)
  • 0 - beginning of line

page down:

  • ctl f - forward a page
  • ctl b - backward a page

editing (in command mode)

  • i - insert, start editing wherever the carrot is
  • o - open a line up (also shift o)
  • a - append

UNDO and REDO (in command mode)

  • u - undo
  • ctl r - redo

cut and paste (two ways: command mode and visual mode)

  • x - delete single character
  • p - paste (also shift p)
  • d - delete + direction command
  • y - copy aka yank + direction command

so you want to copy a word, combine the cut, copy, delete command with a navigation command:

yw - yank word dw - delete word

common shortcuts

yy - yank whole line dd - delete whole line [shift]d - delete the rest of the line from the cursor [shift]y - yank the rest of line from the cursor

Clone this wiki locally