HELP
:h[elp] keyword
- open help for keywordK
- open man page for word under the cursorEXITING
:x or ZZ
writes (only if changes are made) and quit the file:wq
writes (even if no changes are made) and quit the file:q
- quit (fails if there are unsaved changes):q! or ZQ
- quit and throw away unsaved changesFILE OPERATIONS
:wq or :x or ZZ
- write (save) and quit:q
- quit (fails if there are unsaved changes):q! or ZQ
- quit and throw away unsaved changes:wq filename.ext
- writes and saves a file with a given name:sav[eas] file
- save file as:ter[minal]
- open a terminal window:w
- write (save) the file, but don't exit:w !sudo tee %
- write out the current file using sudo:wqa
- write (save) and quit on all tabs<aside>
💡 Tip Run vimtutor
in a terminal to learn the first Vim commands.
</aside>
<aside> 💡 Writing a file modifies its timestamp
</aside>
CURSOR MOVEMENT
h
- move cursor leftj
- move cursor downk
- move cursor upl
- move cursor rightQUICK MOVEMENT
%
- move to matching character (default supported pairs: '()
', '{}
', '[]
' - use :h matchpairs
in vim for more info)^
- jump to the first non-blank character of the line$
- jump to the end of the lineg_
- jump to the last non-blank character of the linegg
- go to the first line of the documentG
- go to the last line of the document5gg
or 5G
- go to line 5DECLARATION MOVEMENT
gd
- move to local declarationgD
- move to global declarationCURSOR MOVEMENT RELATIVE TO SCREEN
H
- move to top of screenM
- move to middle of screenL
- move to bottom of screenzz
- center cursor on screenCONTENT MOVEMENT
w
- jump forwards to the start of a wordW
- jump forwards to the start of a word (words can contain punctuation)`e
- jump forwards to the end of a wordE
- jump forwards to the end of a word (words can contain punctuation)b
- jump backwards to the start of a wordB
- jump backwards to the start of a word (words can contain punctuation)ge
- jump backwards to the end of a wordgE
- jump backwards to the end of a word (words can contain punctuation)REPEAT MOVEMENT
;
- repeat previous f, t, F or T movement,
- repeat previous f, t, F or T movement, backwardsOCURRENCE MOVEMENT
fx
- jump to next occurrence of character xtx
- jump to before next occurrence of character xFx
- jump to previous occurrence of character xTx
- jump to after previous occurrence of character xSCREEN MOVEMENT
Ctrl + e
- move screen down one line (without moving cursor)Ctrl + y
- move screen up one line (without moving cursor)Ctrl + b
- move back one full screenCtrl + f
- move forward one full screenCtrl + d
- move forward 1/2 a screenCtrl + u
- move back 1/2 a screenPARAGRAPH MOVEMENT
}
- jump to next paragraph (or function/block, when editing code){
- jump to previous paragraph (or function/block, when editing code)<aside>
💡 Tip Prefix a cursor movement command with a number to repeat it. For example, 4j
moves down 4 lines.
</aside>
BASIC INSERTION
i
- insert before the cursorI
- insert at the beginning of the linea
- insert (append) after the cursorA
- insert (append) at the end of the lineNEWLINE INSERTION
Ctrl + j
- begin new line during insert modeAUTO-COMPLETE INSERTION
Ctrl + n
- insert (auto-complete) next match before the cursor during insert modeCtrl + p
- insert (auto-complete) previous match before the cursor during insert modeEXIT INSERT MODE
Esc
- exit insert modeCtrl + c
- exit insert modeCtrl + [
- exit insert modeAPPEND
o
- append (open) a new line below the current lineO
- append (open) a new line above the current lineDELETION
Ctrl + h
- delete the character before the cursor during insert modeCtrl + w
- delete word before the cursor during insert modeINDENTATION
Ctrl + t
- indent (move right) line one shiftwidth during insert modeCtrl + d
- de-indent (move left) line one shiftwidth during insert modeREGISTER INSERTION
Ctrl + rx
- insert the contents of register xTEMPORAL NORMAL MODE
Ctrl + ox
- Temporarily enter normal mode to issue one normal-mode command x.BASIC VISUAL MODE
v
- start visual mode, mark lines, then do a command (like y-yank)V
- start linewise visual modeCtrl + v
- start visual block modeMOVEMENT
o
- move to other end of marked areaO
- move to other corner of blockEXIT VISUAL MODE
Esc
- exit visual mode<aside>
💡 Tip Instead of b
or B
one can also use (
or {
respectively.
</aside>