You are on page 1of 1

Vim Cheatsheet

Working With Files Editing


vim <filename> Open a file in Vim i Insert mode. Esc to normal mode.
:w Save a file o Insert new line below
:q Quit a file O Insert new line above
:wq Save and quit I Insert at beginning of line
:q! Quit without saving A Insert (append) at end of line
ZZ Save (if modified) and exit x Delete character
:w <filename> Save a copy as filename dd Delete line
2dd Delete two lines
Vim Modes 5x Delete 5 characters
Esc Normal mode. Default starting mode. dG Delete from cursor to end of file
i Insert mode. Esc to normal mode. d$ Delete from cursor to end of line
v Visual mode. Esc to normal mode. dgg Delete from cursor to beginning of file
: Command-line mode. Esc to normal mode. yy Yank (copy) a line

Navigating Visual Mode


Arrow keys Move around (or h,j,k,l---left, down, up, right) v Enter Visual mode
$ End of line Arrow keys Highlight text in Visual mode
0 Beginning of line (this is a ‘zero’, not an ‘o’) y Yank (copy) selection
Ctrl + u Half-page up c Change (cut) selection
Ctrl + d Half-page down d Delete selection
b Backwards a word p Paste selection. Esc to enter normal mode to paste.
w Forward a word Esc Enter normal mode
G Bottom of file
gg Top of file(or 1G) Build Efficiency
:set number Display line numbering u Undo (from normal mode)
:set nonumber Hide line numbering Ctrl + r Redo (from normal mode)
:5 Go to line 5 /searchterm Search for searchterm. Add \c for case insensitive.
n Next instance of searchterm
Vimdiff N Previous instance of searchterm
vimdiff <file1> <file2> Compare file1 (left) and file2 (right) :%s/replaceme/withme/g Replace "replaceme" with "withme" in the entire file
]c Go to next diff :%s/replaceme/withme/gc Replace "replaceme" with "withme" and prompt
[c Go to previous diff :set paste Disable auto-indent upon paste
dp Diff put :set nopaste Re-enable auto-indent upon paste
do Diff get ?searchterm Search backwards in file for searchterm
:diffupdate Rescan files for changes . Repeat last change
Ctrl + ww Switch between split windows

You might also like