Vim Commands Cheat Sheet

The best and most complete Vim Cheat Sheet. A concise Vim cheat sheet, packed with commands and shortcuts to boost your coding efficiency, whether you're a beginner or seasoned developer.

NOTE: ^ means use Control as the modifier key. So ^u would mean Control + u

Navigation

Moving Left

h - previous character.

b - previous word.

B - previous WORD.

^ - first non-blank character.

0 - beginning of line.

Moving Right

l - next character.

e - end of word.

W - beginning of next WORD.

E - end of WORD.

W - beginning of next WORD.

$ - end of line.

Moving Up

k - up one line.

^u - up half a page.

^b - up one page.

gg - first line.

Moving Down

j - down one line.

^d - down half a page.

^f - down one page.

G - last line.

Jump

fx - jump to next occurrence of characterx.

tx - jump to before next occurrence of characterx.

Fx - jump to previous occurrence of characterx.

Tx - jump to after next occurrence of characterx.

; - repeat previous f, t, F or T movement.

, - repeat previous f, t, F or T movement backwards.

} - jump to next paragraph.

} - jump to previous paragraph.

Align / Move Screen

H - move to the high part of the screen.

M - move to the middle part of the screen.

L - move to the lower part of the screen.

zt - scroll so current line is a the top of the screen.

zb - scroll so current line at the bottom of the screen.

zz - center cursor on screen.

^e - move screen down one line.

^y - move screen up one line.

^b - move back one full screen.

^f - move forward one full screen.

^d - move forward half a screen.

^u - move backward half a screen.

Mark / Position

:marks - view list of marks.

maa - set current position for marka.

`a - jump to position of marka.

y`a - yank text to location of marka.

`0 - go to location where you last quit VIM.

`" - move to the location of last edit in this file.

`. - move to the location of last change in the file.

`` - go to location before last jump.

:ju[mps] - list of jumps.

^i - go to most recent location in jump list.

^o - go to previous location in jump list.

:changes - list of changes.

g, - go to newer position in jump list.

g; - go to previous location in jump list.

^] - jump to the tag under cursor.

vim +5 [file_name] - open [file_name] in VIM and jumpt to line 5.

vim + [file_name] - open [file_name] in VIM and jump to end of the file.

Editing

Insert Mode

i - before the cursor.

I - beginning of the line.

a - after the cursor.

A - end of the line.

o - append a new line below the current line in insert mode.

O - append a new line above the current line in insert mode.

ea - insert at the end of the word.

s - substitute character.

S - substitute line.

C - substitute line from cursor.

^j - begin new line (during insert mode).

Visual Mode

v - start visual mode at cursor.

V - start visual mode and select entire line.

^v or ^q - start visual block mode.

gv - reselect last selected area.

o - while in Visual mode: move to the opposite end of selected area.

Paste

p - paste after cursor.

P - paste before cursor.

gp - paste after cursor and leave cursor after new text.

gP - paste before cursor and leave cursor after the new texst.

Undo | Redo | Repeat

u - undo.

^r - redo.

. - repeat.

2j - move down 2 lines.

Yank (Copy)

y - yank (copy) selected text.

Y or y$ - yank until the end of line.

yy - yank current line.

2yy - yank two lines.

yw - yank from cursor to start of next word.

yiw - yank word under cursor.

yaw - yank word under cursor and space after or before it.

yi> - yank inside brackets.

"aya - yank into registera.

"ayya - yank current line into registera.

0 - last yank.

"+y - during visual mode: yank selected text to system clipboard.

Autocomplete

^n - autocomplete current word, also moves foward autocomplete list.

^p - moves backwards on autocomplete list.

^x ^o - omnicomplete.

^n - during insert mode: insert autocomplete next match before cursor.

^p - during insert mode: insert autocomplete previous match before cursor.

Delete

d - delete selection in Visual mode.

dd - delete current line.

dw - delete from cursor to start of the next word.

D - delete from cursor to the end of current line.

dtx - delete from cursor to x.

2dd - delete 2 lines.

x - delete character under cursor.

r - replace character under cursor.

s - substitute character.

S - substitute line.

C - delete the rest of the line and enter Insert mode.

cw - delete from cursor to next word and enter Insert mode.

c) - delete from cursor to the next paragraph and enter Insert mode.

c}) - delete from cursor to the next paragraph and enter Insert mode.

^w - during Insert mode: delete word before cursor.

^u - during Insert mode: delete line before cursor in Insert mode.

^h - during Insert mode: delete character before cursor.

^t - during Insert mode: indent line shiftwidth to right.

^d - during Insert mode: unindent line shiftwidth to left.

Indent

>> - indent current line.

<< - de-indent current line.

>aB - indent current block inside of curly braces.

>ap - indent current paragraph.

>i{ - indent inside current set of curly braces .

>% - indent a block with () or {}.

>ib - indent inner block with ().

>at - indent a block with <> tags.

2== - re-indent 2 lines.

=% - re-indent a block with () or {}.

=iB - re-indent inner block with {}.

gg=G - re-indent entire buffer.

]p - paste and adjust indent to current line.

^t - during Insert mode: unindent line shiftwidth to left.

^d - during Insert mode: unindent line shiftwidth to left.

> - during Visual mode: indent selected lines.

< - during Visual mode: unindent selected lines.

= - during Visual mode: reformat selected text.

Replace Text

J - join current line to the one below with a space between.

gJ - join current line to the one below without a space between.

~ - toggle upper/lower case of character under cursor.

rx - replace character under cursor with x.

R - enter overtype mode.

ci" - replace text inside quotes (not including quotes) and enter Insert mode.

ca" - replace text around quotes (including quotes) and enter Insert mode.

cit - replace content inside tags and enter insert mode.

cis - replace inside sentence and enter insert mode.

cip - change inside paragraph (does not include blank line) and enter Insert Mode on .

cap - replace paragraph (includes blank space) and enter Insert mode.

ci< - change tag name (between opening and closing angle brackets) and enter Insert mode.

ca< - change tag name (between opening and closing angle brackets) and enter Insert mode.

ci( - replace text inside parentheses and enter Insert mode.

ci{ - replace text inside curly braces and enter Insert mode.

ci[ - replace text inside square brackets and enter Insert mode.

ctchar - replace from cursor and enter Insert mode after char.

:%s/x/y/g - replace all x with y through file.

:3,8s/x/y/g - replace all x with y from line 3 to 8.

:%s/x/y/gc - replace all x with y throughout file with confirmation.

Workflows

Buffers

:ls - open list of buffers.

:bn - switch to next buffer.

:bp - switch to previous buffer.

:bd - close current bufer.

:b# - switch to buffer index #.

:e[dit][file] - open a new buffer and edit [file].

:sp[lit] - open a new buffer in a new split window.

:vsp[lit] - open a new buffer in a new vertically split window.

:vert[ical] ba[ll] - open a new buffer in a new vertically split window.

:tab ba[ll] - edit all buffers as tabs.

Macros

qa - start recording keystrokes to register a.

q - stop recording.

@a - execute contents of register a.

@@a - rerun contents of register a.

2@a - execute twice the contents of register a.

Useful Commands

:w - write (save) file.

:q - quit Vim.

:q! - force quit Vim without saving.

:wq - write (save) file and quit Vim.

:vimtutor - use it to learn your first Vim commands.

:syntax on - turn on syntax highlighting.

:set number - turn on line numbers.

:set wrap - turn on line wrapping.

:set nowrap - turn off line wrapping.

:abbrabbr abbreviation - Add abbr as abbreviation of abbreviation, example abbr abbreviation.

:set incsearch - dynamically show matches without hitting enter.

Diff

vimdiff[file1] [file2] - Use synchronized split windows to diff [file1] [file2].

]c - in VimDiff mode: move to next line with differences.

[c - in VimDiff mode: move to previous line with differences.

:diffthis - make current window part of diff.

:dif[fupdate] - update differences.

:diffo[ff] - switch off diff mode for current window.

Windows

:split - horizontally split window.

:vsplit - vertically split window.

:split[file_name] - split window and in a new window, open [file_name].

:close - close current window.

:only - close all windows, except current window.

^w h - switch focus to left window.

^w j - switch focus to window below.

^w k - switch focus to window above.

^w l - switch focus to right window.

^w w - switch focus to the window below & right.

^w W - switch focus to the window above & left.

^w s - split window.

^w v - split window vertically.

^w q - close active window.

^w x - swap current window position with the next one.

^w = - make all windows equal height/width.

^w H - make current window full height at far left.

^w L - make current window full height at far right.

^w J - make current window full width at bottom most horizontal window.

^w K - make current window full width at top most horizontal window.

Tabs

:tabsnew - open a file in a new tab.

:tabe - open a new tab.

:tabe[file_name] - in a new tab, open [file_name].

:tabc - close current tab.

gt - switch to next tab.

gT - switch to previous tab.

#gt - switch to tab index #.

:tabm[ove]#gt - move current tab to position #.

:tabc[lose] - close current tab and all its windows.

:tab[only] - close all tabs except for the current one.

:tab ba[ll] - edit all buffers as tabs.

Files & Directories

:e! - reload current file without saving.

:r[file_name] - insert the contents of [file_name].

:pwd - print working directory to status line.

:cc[dir] - change working directory to [dir].

:r!date - insert the results from the date Unix command.

Folding

:fold - during Visual mode: fold selected lines.

#zF - fold # lines.

zo - open current fold under cursor.

zc - close current fold under the cursor.

za - toggle current fold under the cursor.

zR - open all folds.

zM - close all folds.

zd - deletes fold under cursor (leaves text intact).

zf - manually define a fold up to motion.

zr - reduce all folds by one level.

zi - toggle folding functionality.

Search

/pattern - search for pattern.

?pattern - search backwards for patternpattern.

\vpattern - magic pattern: non-alpha numeric character are interpreted as special regex symbolspattern.

n - repeat search in same direction.

N - repeat search in opposite direction.

* - search for current word under the cursor.

# - search for current word under cursor, moving backwards.

:noh[lsearch] - remove highlighting of search matches.

:vimgrep /^<h1/ *.html - find lines that start with <h1 in all HTML files in the current directory ( matches appear in the quickfix list).

:cn - move to the next entry in the quickfix list.

:cp - move to the previous entry in the quickfix list.