Skip to main content

Vim cheat sheet


Vim cheat sheet and reference guide. Also includes shortcuts and commands for NERDTree and Vimium. List of essential Vim commands.

Introduction #

Welcome to your ultimate Vim cheat sheet and reference guide! It does not only cover Vim commands, but also delves into two popular plugins, NERDtree and Vimium, to help you streamline your workflow.

Whether you are a seasoned Vim user or just starting out, this cheat sheet will provide you with the commands you need to master the versatile text editor. Sit back, grab your favorite text editor, and let’s dive in!

Vim cheats #

Cursor movement #

Vim cursor movement commands for efficient navigation within a document.

Vim cursor movement/navigation commands.
wjump by start of words (punctuation considered words)
Wjump by words (spaces separate words)
ejump to end of words (punctuation considered words)
Ejump to end of words (no punctuation)
bjump backward by words (punctuation considered words)
Bjump backward by words (no punctuation)
gejump backward to end of words
0(zero) start of line
^first non-blank character of line
$end of line
-line upwards on the first non blank character
+line downwards on the first non blank character
<enter>line downwards on the first non blank character
gggo to first line
Ggo to last line
nGgo to line n
:ngo to line n
)forward to the next sentence.
(backward by a sentence.
{a paragraph backwards
}a paragraph forwards
]]a section forwards or to the next {
[[a section backwards or the previous {
CTRL-fforward by a screen of text
CTRL-bbackward by a screen of text
CTRL-uup by half a screen
CTRL-ddown by half a screen
Hto the top of the screen.
Mto the middle of the screen.
Lto the bottom of the screen.
fxsearch line forward for 'x'
Fxsearch line backward for 'x'
txsearch line forward before 'x'
Txsearch line backward before 'x'

Bookmarks #

Vim bookmarks are named markers that allow users to quickly jump to specific locations in a document.

Vim bookmark commands.
:markslist all the current marks
mamake a bookmark named a at the current cursor position
`ago to position of bookmark a
'ago to the line with bookmark a
`.go to the line that you last edited

Insert mode #

Vim insert mode is a mode in which characters typed by the user are inserted into the document at the cursor position.

Vim insert mode commands.
istart insert mode at cursor
Iinsert at the beginning of the line
aappend after the cursor
Aappend at the end of the line
oopen (append) blank line below current line
Oopen blank line above current line
Esc"exit insert mode

Editing #

Vim editing commands are a set of operations that modify text in Vim, such as inserting, deleting, copying, and replacing text.

Vim commands for text editing.
rreplace a single character (does not use insert mode)
Rreplace characters rather than inserting
Jjoin line below to the current one
ccchange (replace) an entire line
cwchange (replace) to the end of word
c$change (replace) to the end of line
sdelete character at cursor and substitute text
Sdelete line at cursor and substitute text (same as cc)
xptranspose two letters (delete and paste
.repeat last command
~switch case
g~iwswitch case of current word
gUiwmake current word uppercase
guiwmake current word lowercase
gU$make uppercase until end of line
gu$make lowercase until end of line
:%retabfix spaces / tabs issues in whole file
:r [name]insert the file [name] below the cursor.
:r !{cmd}"execute cmd & insert its standard output below cursor.

Indentation #

Vim commands for text indentation.
gg=Gauto indent whole file
>>increase line indent
5>>increase indent of 5 lines
<<decrease line indent
==auto-indent current line
5==auto-indent 5 lines
>%increase indent of bracketed block (cursor on bracket)
<%decrease indent of bracketed block (cursor on bracket)
=%auto indent a bracketed block (cursor on bracket)
]ppaste text
=i{auto-indent 'inner block' (contents of the block)
=a{auto-indent 'a block' (block and containing braces)
=2a{auto-indent '2 blocks' (this block & containing block)
>i{increase inner block indent
<i{"decrease inner block indent

Deleting #

Vim commands for deleting text.
xdelete current character
Xdelete previous character
dwdelete the current word
dddelete (cut) a line
Ddelete from cursor to end of line
dt*delete (cut) from cursor to next occurence of *
:[range]ddelete [range] lines

Copying and moving text #

Vim commands for copying and moving (pasting) text.
ywyank word
yiwyank word under cursor
yyyank (copy) a line
2yyyank 2 lines
y$yank to end of line
pput (paste) the clipboard after cursor/current line
Pput (paste) before cursor/current line
:set pasteavoid unexpected effects in pasting
:registersdisplay the contents of all registers
"xywyank word into register x
"xyyyank line into register x
:[range]y xyank [range] lines into register x
"xpput the text from register x after the cursor
"xPput the text from register x before the cursor
"xgplike "p
"xgPlike "P
:[line]put x"put the text from register x after [line]

Macros #

Vim macros commands
qastart recording macro 'a'
qend recording macro
@areplay macro 'a'
@:"replay last command

Visual mode #

Vim visual mode
vstart visual mode
Vstart linewise visual mode
omove to other end of marked area
Uupper case of marked area
CTRL-vstart visual block mode
Omove to other corner of block
awmark a word
aba () block (with braces)
aba {} block (with brackets)
ibinner () block
ibinner {} block
Escexit visual mode

Visual mode commands #

Vim visual mode commands
>shift right
<shift left
cchange (replace) marked text
yyank (copy) marked text
ddelete marked text
~switch case

Spelling #

Vim spelling and spell check commands
]snext misspelled word
[sprevious misspelled word
zgadd word to wordlist
zugundo last add word
z=suggest word

Search and replace #

Vim search and replace commands
:s/foo/bar/greplace all foo with bar in current line
:%s/foo/bar/greplace all foo with bar throughout file
:%s/foo/bar/gcreplace all foo with bar with confirmation
:%s/Foo/Bar/gcIreplace all Foo with Bar (case sensitive)
:argdo %s/foo/bar/gcopen multiple files and run this command to replace foo with bar in every file with confirmation

Vimgrep #

Syntax: :vim[grep] [pattern] [scope]

Vimgrep commands
:pwdgrep operates from present working directory ($PWD)
:vimgrepinvoke (internal) grep
:viminvoke (internal) grep
:vim /foo/g %find occurrences of foo in current document
:vim /foo/g **/*recursively find occurrences of foo in $PWD

Quickfix #

Vimgrep quickfix commands
:clopen quickfix list
:copeopen quickfix list
:cnextmove to next count/result (quickfix can be closed)
:cnmove to next count/result (quickfix can be closed)
:cprevmove to previous count/result (quickfix can be closed)
:cpmove to previous count/result (quickfix can be closed)
:cfirstmove to first count/result (quickfix can be closed)
:clastmove to last count/result (quickfix can be closed)

Working on multiple files #

Vim multiple-file commands
:e filenameedit a file in a new buffer
:tabe filenameedit a file in a new tab
:lslist all buffers
:bngo to next buffer
:bpgo to previous buffer
:bddelete a buffer (close a file)
:b1show buffer 1
:b vimrcshow buffer whose filename begins with 'vimrc'

Programming #

Vim programming commands
%show matching brace
gfedit file whose name is under/after the cursor
gdjump to declaration local variable/function if cursor is on
''return to line where cursor was before latest jump
gireturn to insert mode where you inserted text last
CTRL-omove to previous position you were at
CTRL-imove to more recent position you were at

Sessions #

Syntax: :mks[ession][!] [file]

Vim session commands
:mksession foo.vimsave session to foo.vim
:mks foo.vimsave session to foo.vim
:mksession! foo.vimsave session to exisiting foo.vim
:mks!overwrite old session with new one
:source foo.vimopen session foo.vim (from within Vim)
vim -S ~/foo.vimstart Vim with the foo.vim session.

Buffers #

Vim buffer commands
CTRL-wwmove between buffers

Tabs #

Vim tab commands
:tabslist all tabs including their displayed windows
:tabm 0move current tab to first
:tabmmove current tab to last
:tabm {i}move current tab to position i+1
:tabngo to next tab
:tabpgo to previous tab
:tabfirstgo to first tab
:tablastgo to last tab
gtgo to next tab
gTgo to previous tab
{i}gtgo to tab in position i

Freeze (scroll lock) #

Vim scroll lock commands
CTRL-senable terminal scroll lock
CTRL-qdisable terminal scroll lock

Typing Ctrl+s in Vim stops all terminal output until Ctrl+q is typed. Vim will appear frozen. That is because of the XON/XOFF control-flow, a software-based flow control mechanism used in serial communication, where XON (Ctrl+Q) is sent to resume data transmission, and XOFF (Ctrl+S) is sent to temporarily halt it. Disable this default behavior of your terminal with stty -ixon.

Exiting #

Vim exit commands
:qquit Vim. Fails when changes have been made.
:q!quit without writing.
:cqquit always
:wqwrite the current file and exit.
:wq!write the current file and exit always.
:wq {file}write to {file}. Exit if not editing the last
:wq! {file}write to {file} and exit always.
:[range]wq[!]same as above
ZZwrite current file
ZQquit current file and exit (same as ":q!").

NERDtree cheats #

Basics #

Basic NERDtree commands
:NERDTreeToggleshow / hide file browser
:NERDTreeFindshow current file in file browser
qclose the NERDTree window
Azoom (maximize-minimize) the NERDTree window
?toggle help
NERDtree navigation commands
Pgo to root
pgo to parent
Kgo to first child
Jgo to last child
CTRL-jgo to next sibling
CTRL-kgo to prev sibling

File system #

NERDtree file system commands
Cchange tree root to the selected dir
umove tree root up a dir
Umove tree root up a dir but leave old root open
rrefresh cursor dir
Rrefresh current root
mhow menu
cdchange the current working directory to the selected dir

Filtering #

NERDtree filtering commands
Ihidden files
ffile filters

Files #

NERDtree commands to work on files
oopen in prev window
topen in new tab
Topen in new tab silently
iopen split
gipreview split
sopen vsplit
gspreview vsplit

Bookmarks #

NERDtree bookmarking commands
:Bookmark namebookmark the current node as 'name'
oopen bookmark
topen in new tab
Topen in new tab silently
Ddelete bookmark

Directories #

NERDtree commands to work on directories
oopen & close node
Orecursively open node
xclose parent of node
Xclose all child nodes of current node recursively
eexplore selected dir

Vimium cheats #

Modifier keys are specified as <c-x>, <m-x>, and <a-x> for ctrl+x, meta+x, and alt+x respectively. For shift+x and ctrl-shift-x, just type X and <c-X>.

Basics #

Basic Vimium commands
?show the help dialog for a list of all available keys
gsview source
ienter insert mode -- all commands will be ignored until you hit Esc to exit
yycopy the current url to the clipboard
yfcopy a link url to the clipboard
venter visual mode
Venter visual line mode
Vimium commands to navigate the current page.
hscroll left
jscroll down
kscroll up
lscroll right
ggscroll to top of the page
Gscroll to bottom of the page
dscroll down half a page
uscroll up half a page
gfcycle forward to the next frame
gFfocus the main/top frame
]], [[Follow the link labeled 'next' or '&gt
gugo up one level in the URL hierarchy
gUgo up to root of the URL hierarchy
geedit the current URL
zHscroll all the way left
zLscroll all the way right
Vimium commands to navigate to new pages.
fopen a link in the current tab
Fopen a link in a new tab
oOpen URL
bOpen bookmark
BOpen bookmark in a new tab
<a-f>open multiple links in a new tab
gEedit the current URL and open in a new tab

Finding #

Vimium commands to find contents.
/enter find mode
ncycle forward to the next find match
Ncycle backward to the previous find match

Type your search query and hit enter to search, or Esc to cancel

Manipulating tabs #

Vimium commands for tab manipulation.
J, gTgo one tab left
K, gtgo one tab right
g0go to the first tab. Use ng0 to go to n-th tab
g$go to the last tab
^visit the previously-visited tab
tcreate tab
ytduplicate current tab
xclose current tab
Xrestore closed tab (i.e. unwind the 'x' command)
Tsearch through your open tabs
Wmove current tab to new window
</b></code></td>pin/unpin current tab </tr> </tbody> </table>

Further readings #

Sources and recommended, further resources on the topic:


Jonas Jared Jacek • J15k

Jonas Jared Jacek (J15k)

Jonas works as project manager, web designer, and web developer since 2001. On top of that, he is a Linux system administrator with a broad interest in things related to programming, architecture, and design. See:


License: Vim cheat sheet by Jonas Jared Jacek is licensed under CC BY-NC-SA 4.0.

This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, for noncommercial purposes only. If others modify or adapt the material, they must license the modified material under identical terms. To give credit, provide a link back to the original source, the author, and the license e.g. like this:

<p xmlns:cc="" xmlns:dct=""><a property="dct:title" rel="cc:attributionURL" href="">Vim cheat sheet</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="">Jonas Jared Jacek</a> is licensed under <a href="" target="_blank" rel="license noopener noreferrer">CC BY-NC-SA 4.0</a>.</p>

For more information see the DITig legal page.

“Users spend most of their time on other sites. This means that users prefer your site to work the same way as all the other sites they already know.”

Jakob Nielsen, Principal and Co-founder of the Nielsen Norman GroupJakob's Law of Internet User Experience, - IT quotes