Modes
Mode Switching
iInsert mode (before cursor)
aInsert mode (after cursor)
oInsert line below and enter insert mode
OInsert line above and enter insert mode
vVisual mode (character)
VVisual mode (line)
Ctrl+vVisual block mode
:Command-line mode
RReplace mode
EscReturn to normal mode
Navigation
Character & Line Motion
h j k lLeft, down, up, right
0 / ^Start of line / first non-blank
$End of line
w / WNext word / WORD
b / BPrevious word / WORD
e / EEnd of word / WORD
f{c} / F{c}Find char forward / backward
t{c} / T{c}Till char forward / backward
Screen & File Motion
gg / GGo to first / last line
:{n}Go to line n
Ctrl+d / Ctrl+uHalf-page down / up
Ctrl+f / Ctrl+bFull page down / up
H / M / LTop / middle / bottom of screen
%Jump to matching bracket
Editing
Insert & Append
IInsert at beginning of line
AAppend at end of line
eaAppend at end of word
giInsert at last insert position
Delete & Change
x / XDelete char under / before cursor
ddDelete line
dwDelete word
d$ / DDelete to end of line
cc / SChange entire line
cwChange word
c$ / CChange to end of line
ci" / ci(Change inside quotes / parens
Copy & Paste
yyYank (copy) line
ywYank word
y$Yank to end of line
p / PPaste after / before cursor
JJoin line below to current line
Undo & Repeat
uUndo
Ctrl+rRedo
.Repeat last command
Search & Replace
Search
/patternSearch forward
?patternSearch backward
n / NNext / previous match
*Search word under cursor (forward)
#Search word under cursor (backward)
Substitute
:s/old/new/ " replace first on line :s/old/new/g " replace all on line :%s/old/new/g " replace all in file :%s/old/new/gc " replace all, confirm each
Visual Mode
Selection
vStart character selection
VStart line selection
Ctrl+vStart block selection
oMove to other end of selection
gvReselect last visual selection
Actions on Selection
dDelete selection
yYank selection
cChange selection
>Indent selection
<Unindent selection
~Toggle case
U / uUppercase / lowercase selection
Buffers & Windows
Buffers
:lsList open buffers
:bn / :bpNext / previous buffer
:b{n}Go to buffer n
:bdClose current buffer
:e fileOpen file in new buffer
Windows
:sp fileHorizontal split
:vsp fileVertical split
Ctrl+w h/j/k/lNavigate to window
Ctrl+w =Equalize window sizes
Ctrl+w qClose window
Tabs
:tabnew fileOpen file in new tab
gt / gTNext / previous tab
:tabcloseClose current tab
Registers
Using Registers
"ayYank into register a
"apPaste from register a
"AyAppend yank to register a
:regShow all registers
Special Registers
""Unnamed (last delete/yank)
"0Last yank
"+System clipboard
"/"Last search pattern
".Last inserted text
"_Black hole (discard)
Macros
Recording & Playing
q{a}Start recording macro into register a
qStop recording
@{a}Play macro from register a
@@Replay last macro
5@aPlay macro a 5 times
Macro Example
qa " start recording into a I// " insert // at line start Esc j " return to normal, move down q " stop recording 10@a " comment next 10 lines
Settings
Common Options
:set number " show line numbers :set relativenumber " relative line numbers :set tabstop=4 " tab width :set expandtab " spaces instead of tabs :set ignorecase " case-insensitive search
Display & Behavior
:set wrap / nowrap " toggle line wrapping :set hlsearch " highlight search matches :set incsearch " incremental search :set cursorline " highlight current line :syntax on " enable syntax highlighting
File Operations
Save & Quit
:wSave
:w fileSave as file
:qQuit (fails if unsaved)
:q!Quit without saving
:wq / :x / ZZSave and quit
:waSave all buffers
:qaQuit all buffers
File Info & External
Ctrl+gShow file info
:!cmdRun shell command
:r !cmdInsert command output
:r fileInsert file contents
Text Objects
Inner & Around Objects
iw / awInner / around word
is / asInner / around sentence
ip / apInner / around paragraph
i" / a"Inner / around double quotes
i' / a'Inner / around single quotes
i( / a(Inner / around parentheses
i{ / a{Inner / around braces
it / atInner / around HTML tag
Common Combos
ciw " change inner word di" " delete inside quotes ya{ " yank around braces vip " select inner paragraph
Marks & Jumps
Marks
m{a}Set mark a at cursor position
'aJump to line of mark a
`aJump to exact position of mark a
:marksList all marks
Jump List
Ctrl+oJump to previous position
Ctrl+iJump to next position
:jumpsShow jump list
''Jump to last jump position