Vim 101

Jon Johnson

$ vimtutor

Normal Mode

Moving around the document

Insert Mode

Typing text

Visual Mode

Selecting text

Muscle Memory

Motions

h, j, k, l left, down, up, right
w word
b back
e end (of word)
$ end of line
^ beginning of line
f{char} forward to {char}
t{char} forward up to {char}

More Motions

gg top of file
G bottom of file
{number}G go to that line
Shift + H/M/L move around the screen (high/middle/low)

Verbs

Character Action
i insert
c change
d delete
a append
s substitute

Shortcuts

Character Action
I (^i) insert at the beginning of the line
C (c$) change till the end of the line
D (d$) delete to the end of the line
A ($a) append at the end of the line
S (0c$) change the whole line

Copy and Paste

Keystrokes Translation
v visualy select text
y copy (yank)
p paste
d delete (cut)

Putting It Together

Keystrokes Translation
dt/ delete up to the first "/"
d$ delete to the end of the line
c2w change 2 words
ci" change inside quotes
da" delete around "
5p put yanked text into buffer 5 times
3dd delete current line three times

Searching

/ search for text
n, N go to next/previous result
* search for this word
:%s/[find]/[replace]/gc subsitute [find] with [replace]

:commands

Command Action
:w [file] write to [file]
:e [file] edit [file]
:sp [file] open [file] in split window
:vs [file] open [file] in vertically split window
:tabedit [file] open [file] in a new tab
:!mkdir foo run stuff in your shell
:make run your makefile

Macros

qa[keystrokes]q save keystrokes to "a"
3@a replay the keystrokes in "a" 3 times
@@ replay last macro

Misc

. repeat
u undo
Ctrl+R redo
zz center screen on cursor
o, O new line below (or above) cursor, insert mode
J join this line with the one below it
Ctrl+N autocompletion
= auto format