VIM Cheatsheet!

Motions & Ranges

Cursor Motions

h
Left
l
Right (Lower "L")
k
Up
j
Down
-
Up and to first non-blank character (k^)
+
Down and to first non-blank character (j^)
space
Right

Within Line

0
To Beginning of Line
$
To End of Line
^
To first non-blank in line
fchar
to next char on line
Fchar
to previous char on line
tchar
move 'til (before) next char
Tchar
move after previous char
;
Repeats line find [fFtT]
,
Reverse line find [fFtT]

Between lines

{
Paragraph Backward
}
Paragraph Forward
(
Sentence Backward
)
Sentence Forward

Match/Pair

%
Moves to matching pair" () {} []...

Within File (Buffer)

nG
To line number n
gg
To first line
G
To last line (End of File)
n%
To n Percent through file
`mark
to defined bookmark
/pattern
forward until pattern reached
?pattern
backward until pattern reached

Word Motions

w
Forward to start of next word
b
Backward to start of word
e
Forward to end of next word
ge
Backward to end of next word

Text Objects

amotion
Around the enclosing object
imotion
Inside the enclosing object
aiw
Around/Inner word
ais
Around/Inner sentence
aip
Around/Inner paragraph
ai"
Around/Inside "string"
ai'
Around/Inside 'string'
ai`
Around/Inside `string`
ai)
Around/Inside (parens)
ai]
Around/Inside [brackets]
ai}
Around/Inside {braces}
ait
Around/Inside tag/block
ai>
Around/Inside tag

Show Location

G
Display position in status
:set number
Shows line numbers
:set nonumber
Turns off line numbers
:set relativenumber
Relative line numbers
:set ruler
Enables curr line/col display
:set cursorline
Highlights current line
:set cursorcolumn
Highlights current column

Marks (Bookmarks)

ma-z
Set a mark in this file
mA-Z
Set a mark avilable in any file
`alphanum
Jump to mark
'alphanum
Jump to start of mark line
``
Jump back to previous position
O
Jump to older position in jump history
I
Jump to newer position in jump history
:marks
List marks
`"
Jump to position of last edit
`.
Jump to position of last change

Ranges

%
All lines
range,range
Start and End points of the range
.
Current line (default range)
$
End of file
/pattern/
Start/End at a matching pattern
?pattern?
previous line matching pattern
line
The given line number (1=first line)
.+lines
Number of lines after current
.-lines
Number of lines before current
$-lines
Number of lines before end of file
'mark
A named mark
'<,'>
The visual block currently selected

Editing Commands

Command Formats

count command
Do command count times
command motion
Do command through target
command count motion
Do command over 2 motions
visual command
Do command over selected area
:range command count
Executes command within a line range a given number of times
.
Repeat previous edit
:'<,'>s/original/replacement/g
Executes command within visually selected range, g (all) lines per line
c2w
Change next "2 words"
c$
Change through "End of Line"
cl
Change "left of cursor"
cG
Change through "End of File"

Insert Edit Mode

command motion...text...ESC Enters edit mode, ESC to end
a
Insert after current cursor (li)
A
Append to current line ($a)
o
open new line under current and edit
O
open new line above current and edit
i
Insert before cursor
I
Insert from beginning of line (0i)

Replace Edit Mode

command motion...text...ESC Enters edit mode, ESC to end
rchar
Replaces current character with new one
R
Enters overtype mode.
cmotion
Change text between cursor and motion
C
Change until End of line (c$)
s
Replace current character with text (xi or cl)
S
Replace current line (0c$)

Delete

dmotion
Deletes from cursor through motion
countdd
Deletes current/next count line(s)
x
Delete character at cursor
X
Delete character before cursor

Repeat/Undo/Redo

.
Repeat last command
u
undo last command
R
Redo last undo
:earlierduration
Undo to state duration ago
:laterduration
Redo to state duration from undo point

Manipulations

> motion
Shift right one indent level
<motion
Shift left one indent level
>>
Shift current line right
<<
Shift current line left
J
Join with next line
count~
Invert case of characters
=motion
Re-indent text cursor to motion
gg=G
Goto Top, re-indent to EOF

Edit Mode Motions

Available when in edit mode
W
Deletes to start of current word
Left
Moves one word left
Right
Moves one word right
Backspace
Deletes previous character

Other Editing

Searching

/pattern
Search forward to pattern
?pattern
Search backward to pattern
#
Search forward for word under cursor
*
Search backward for word under cursor
n
Next occurrence
N
Previous occurrence
:set hlsearch
highlight matches
:set nohlsearch
don't highlight matches
:set incsearch
Incremental find
:set noincsearch
Turn off Incremental find
:set wrapscan
Turn on wrap-around search
:set nowrapscan
Turn off wrap-around search

Substitution

:ranges/pattern/text/<flags
Substition text for pattern
:%s/from/to/
% range for all lines
:%s/from/to/g
g flag for global
:%s/from/to/c
c flag for confirmation/^\.

Cut, Copy, Paste

Moves files between a-z named & special registers
registerCommand motion
Uses default/unnanmed register
"a-z registerCommand motion
Uses named register
"A-Z registerCommandy
Appends to named register
visual"a-z registerCommand
Uses visual selection
ymotion
Yank (Copy) to register
Y
Yank Current Line
p
Put (Paste) after cursor
dmotion
Deletes (Cuts) text

Special Paste Registers

p
Unnamed Register
"_p
Black hole register
"digitp
Read-only 0-9 history, 0=most recent
"-p
Small delete register (last small change/delete)
".p
Last insert register
"%p
Current buffer file name
":p
Last executed :ex command
"/p
Last search pattern
"=expression Enter p
Expression evaluation register
"*p
System Clipboard (usually just GUI)
:reg
Display Registers

Folding

zfmotion
Fold lines from cursor to motion
zo
Open fold at cursor
zc
Close fold again around cursor
zr
Reduce folds by level
zR
Reduce all levels of folds
zM
More refold levels
zm
Refold all

Visual Selection and Mode

Visual mode selects text for editing
selection command
vmotions
Enters stream selection mode
Vmotions
Enters line selection mode
V
Enters block selection mode
I
Inserts text at left of each block line
>
Shifts block right
<
Shifts block left
U
Uppercases letters in selection
u
Lowercases letters in selection
~
Lowercases letters in selection

File and Buffers

Files

:edit filename
Loads file for editing
:wall
Writes all files
:w
Saves file
:args files
Loads list into args list
:quit
quits editing file
:quit!
quits editing file, abondons changes
ZZ
Save and Quit file

Buffers

:next
Go to next file
:wnext
Save file and go to next file
:previous
Go to previous file
:wprevious
Writes then goes to prev file
:ls
List buffers (also :buffers)
:b n
Go to buffer number n

Macro

qletter
Records to letter register
@letter
Run recorded macro

Window (Pane) & Tabs

Scrolling

F
Page Forward (Down)
B
Page Backward (Up)
D
Half-Page Forward (Down)
U
Half-Page Backward (Up)
E
1 Line Forward (Down)
Y
1 Line Backward (Up)
zt
Scroll cursor line to Top
zb
Scroll cursor line to Bottom
zz
Scroll cursor line to middle

Splitting

W S
Splits window horizontally ----
W V
Splits window Vertically |
W N
Horiz Split, new buffer
W Q
Close (Quit) Window
W O
Only: Close all other windows

Switch Window

W W
Next window
W P
Previous window
W direction
Switch to pane at direction
W T
Top window
W B
Bottom window

Rotate

W R
Rotate window down/right
W X
Exchange with next window
W direction
Move to pane at direction

Sizing

W=
Equal sizes
W count-
Decrease size count lines
W count+
Increase size count lines
W count <
Decrease size count cols
W count>
Increase size count cols
W|
Verical resize

Window Tabs

:tabedit filename
Opens file in new tab
:tabclose http://vim.wikia.com/wiki/Ranges
Closes tab
PgUp
Next tab
PgDn
Previous tab

Janus & Common Extensions

NERDTree

o
Open file (Also Enter)
t
Open in Tab
T
Open in new tab silently
i
Open in a new Split
s
Open in a new Veritical Split
x
Close file
r
Refresh node
R
Refresh root

Rails

gf
Go to file under cursor
:A
Go to Alterneta file
:AS ... In split
:AT ... In tab
R
Go to Related file (RS, RT)

Unimpaired

n]q
Next Error
n[q
Previous Error
[space
Add blank line above cursor
[space
Add blank line below cursor
[os
Set spell (]os nospell)
[f
go to next file in directory (]f previous)
]f
go to previous file in directory

CtrlP (Fuzzy File Open)

:CtrlP
Open CtrP (Map to a Key!)
F5
Refresh file list
F Change Modes (file, buffer, MRU)
D Filename only search
R Regex Mode
J Navigate Down
K CNavigate Up
ENTER
Open select file
T Open in new Tab
V Open in Veritcal Split
X Open in Split
Z Mark file for multiple open
O Open multiple marked files
Y Create new file and parent dirs

Nerd Commenter (Visual Mode)

Leaderc
Toggles comment state
Leadercc
Comment out Lines
Leadercu
UnComment Lines
Leadercn
Comment, force nesting
Leadercb
Comment Block, left-aligned
Leadercs
Comment sexily
Leaderc$
Comment out to end of line
LeadercA
Append comment

Surround

editsfrom to Edit Surrounding delimiter
editstextobject Like "iw" or "o)"
cs"'
Change surrounding quotes from " to '
cstdiv Change surrounding tag to div
ds"
Delete surrounding quotes
ysiw[
Enclose word with brackets, "[ word ]"
ysiw]
Enclose word with brackets, "[word]"

Git Fugitive

:Gwrite
Add to staged files
:Gread
Revert to last checked-in
:Gremove
Delete file and buffer
:Gmove
Rename file
:Gdiff
Vimdiff against index
:Gblame
Show last commit of lines
:Glog
Loads revision history
:Ggrep term
Searches the repo for term
:Ggrep term tag
Searches the tag for term
:Ggrep term SHA
Searches the SHA for term

zoomwin

Wo
Zoom into/out of full screen

gist

:rangeGist
Posts buffer/file or range to gist
:Gist -p
Public gist
:Gist -m
Gist with all open buffers

buffergator

leaderb
Open Buffer list

vim-multiple-cursors

N
Starts multi-cursor mode