Vim Cheatsheet
Introduction
This cheatsheet contains must know vim tips and tricks.
Navigation
Horizontal Navigation
h, j, k, l: left, down, up, rightw: next wordb: prev (back) word0: Beginning of line^: First char of line$: End of lineg_: Last char on linef<char>: Search for char in current line (;to repeate)F<char>: Search backward for char in current line (;to repeate)t<char>: Search until the char in current line (;to repeate)T<char>: Search backward until the char in current line (;to repeate)
Vertical Navigation
gg: First LineG: Last LineH: Move cursor to TopM: Move cursor to MiddleL: Move cursor to Bottomzz: Move line to Middlezt: Move line to Topzb: Move line to BottomC-y: Scroll up by one lineC-e: Scroll down by one lineC-u: Scroll up by half pageC-d: Scroll down by half pageC-b: Scroll up by full pageC-f: Scroll down by full page*: search forward for word under cursor#: search backward for word under cursor%: jump to matching parentheses
Buffers
:ls: List all Buffers:b<num>: Goto<num>buffer:bnext: Goto next buffer:bprev: Goto prev bufferC-^: Goto alternate buffer
Window Navigation
C-w: Start “window mode”C-w+v: Vertical SplitC-w+s: Horizontal SplitC-w+w: Other WindowC-w+p: Previous WindowC-w+q: Close Window
Marks
ma: Set mark (stores it in rega)'a: Goto the first char of line of marka- `a : Goto the mark
a [': Goto next mark (does not wrap)]': Goto prev mark (does not wrap)mA: Capital letter marks work even from different file:marks: See all marks:delmarks a,A: Delete marksaandA:delmarks!: Delete all lowercase marks
Registers
Copy/Delete/Paste
"ayw: Copy word toaregister"adw: Delete/Cut word toaregister"ap: Paste contents ofaregister
Macros
q<reg>: Start recording macro in<reg>.qto stop recording@<reg>: Run macro from<reg>- Made a mistake in long macro and want to re-record it?
- Paste it in buffer, edit it and yank back in
<reg>
- Paste it in buffer, edit it and yank back in
Insert Mode
Repeating chars
C-o 10i # <ESC>
Paste
C-rand register to insert text from register e.g.C-r+": Inserts last yanked test..register stores last typed text. e.g.C-r+.: Inserts last typed text.C-a: Short forC-r+.
Completion
- Start completion with
C-p. Cycle through it usingC-pandC-n. Completions are taken fromcompletesetting.:set complete: See currentcompletesetting.set complete=.,w,b,u,t,i,kspell - Tag completion:
C-x+C-]C-xputs you into Completion Mode.C-]will search for only in ctags file. - File completion:
C-x+C-fIt completes recursively! - Context-aware completion:
C-x+C-pandC-x+C-n - Context-aware Line completion:
C-x+C-l
Misc
C-a: Increment number under cursorC-x: Decrement number under cursorg+C-a: Try and find out!