Vim cheat sheet
Published: 2015-11-26
Updated: 2023-12-24 Summary Vim cheat sheet and reference guide. Also includes shortcuts and commands for NERDTree and Vimium. List of essential Vim commands.
Table of contents Introduction Vim cheats Cursor movement Bookmarks Insert mode Editing Indentation Deleting Copying and moving text Macros Visual mode Visual mode commands Spelling Search and replace Vimgrep Quickfix Working on multiple files Programming Sessions Buffers Tabs Freeze (scroll lock) Exiting NERDtree cheats Basics Navigation File system Filtering Files Bookmarks Directories Vimium cheats Basics Navigating the current page Navigating to new pages Finding Manipulating tabs Further readings 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. Command Explanation h
left j
down k
up l
right w
jump by start of words (punctuation considered words) W
jump by words (spaces separate words) e
jump to end of words (punctuation considered words) E
jump to end of words (no punctuation) b
jump backward by words (punctuation considered words) B
jump backward by words (no punctuation) ge
jump 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 gg
go to first line G
go to last line nG
go to line n :n
go 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-f
forward by a screen of text CTRL-b
backward by a screen of text CTRL-u
up by half a screen CTRL-d
down by half a screen H
to the top of the screen. M
to the middle of the screen. L
to the bottom of the screen. fx
search line forward for 'x' Fx
search line backward for 'x' tx
search line forward before 'x' Tx
search 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. Command Explanation :marks
list all the current marks ma
make a bookmark named a at the current cursor position `a
go to position of bookmark a 'a
go 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. Command Explanation i
start insert mode at cursor I
insert at the beginning of the line a
append after the cursor A
append at the end of the line o
open (append) blank line below current line O
open 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. Command Explanation r
replace a single character (does not use insert mode) R
replace characters rather than inserting J
join line below to the current one cc
change (replace) an entire line cw
change (replace) to the end of word c$
change (replace) to the end of line s
delete character at cursor and substitute text S
delete line at cursor and substitute text (same as cc) xp
transpose two letters (delete and paste u
undo CTRL-r
redo .
repeat last command ~
switch case g~iw
switch case of current word gUiw
make current word uppercase guiw
make current word lowercase gU$
make uppercase until end of line gu$
make lowercase until end of line :%retab
fix 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. Command Explanation gg=G
auto 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) ]p
paste 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. Command Explanation x
delete current character X
delete previous character dw
delete the current word dd
delete (cut) a line D
delete from cursor to end of line dt*
delete (cut) from cursor to next occurence of * :[range]d
delete [range] lines
Copying and moving text # Vim commands for copying and moving (pasting) text. Command Explanation yw
yank word yiw
yank word under cursor yy
yank (copy) a line 2yy
yank 2 lines y$
yank to end of line p
put (paste) the clipboard after cursor/current line P
put (paste) before cursor/current line :set paste
avoid unexpected effects in pasting :registers
display the contents of all registers "xyw
yank word into register x "xyy
yank line into register x :[range]y x
yank [range] lines into register x "xp
put the text from register x after the cursor "xP
put the text from register x before the cursor "xgp
like "p "xgP
like "P :[line]put x
"put the text from register x after [line]
Macros # Vim macros commands Command Explanation qa
start recording macro 'a' q
end recording macro @a
replay macro 'a' @:
"replay last command
Visual mode # Vim visual mode Command Explanation v
start visual mode V
start linewise visual mode o
move to other end of marked area U
upper case of marked area CTRL-v
start visual block mode O
move to other corner of block aw
mark a word ab
a () block (with braces) ab
a {} block (with brackets) ib
inner () block ib
inner {} block Esc
exit visual mode
Visual mode commands # Vim visual mode commands Command Explanation >
shift right <
shift left c
change (replace) marked text y
yank (copy) marked text d
delete marked text ~
switch case
Spelling # Vim spelling and spell check commands Command Explanation ]s
next misspelled word [s
previous misspelled word zg
add word to wordlist zug
undo last add word z=
suggest word
Search and replace # Vim search and replace commands Command Explanation :s/foo/bar/g
replace all foo with bar in current line :%s/foo/bar/g
replace all foo with bar throughout file :%s/foo/bar/gc
replace all foo with bar with confirmation :%s/Foo/Bar/gcI
replace all Foo with Bar (case sensitive) :argdo %s/foo/bar/gc
open multiple files and run this command to replace foo with bar in every file with confirmation
Vimgrep # Syntax: :vim[grep] [pattern] [scope]
Vimgrep commands Command Explanation :pwd
grep operates from present working directory ($PWD) :vimgrep
invoke (internal) grep :vim
invoke (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 Command Explanation :cl
open quickfix list :cope
open quickfix list :cnext
move to next count/result (quickfix can be closed) :cn
move to next count/result (quickfix can be closed) :cprev
move to previous count/result (quickfix can be closed) :cp
move to previous count/result (quickfix can be closed) :cfirst
move to first count/result (quickfix can be closed) :clast
move to last count/result (quickfix can be closed)
Working on multiple files # Vim multiple-file commands Command Explanation :e filename
edit a file in a new buffer :tabe filename
edit a file in a new tab :ls
list all buffers :bn
go to next buffer :bp
go to previous buffer :bd
delete a buffer (close a file) :b1
show buffer 1 :b vimrc
show buffer whose filename begins with 'vimrc'
Programming # Vim programming commands Command Explanation %
show matching brace gf
edit file whose name is under/after the cursor gd
jump to declaration local variable/function if cursor is on ''
return to line where cursor was before latest jump gi
return to insert mode where you inserted text last CTRL-o
move to previous position you were at CTRL-i
move to more recent position you were at
Sessions # Syntax: :mks[ession][!] [file]
Vim session commands Command Explanation :mksession foo.vim
save session to foo.vim :mks foo.vim
save session to foo.vim :mksession! foo.vim
save session to exisiting foo.vim :mks!
overwrite old session with new one :source foo.vim
open session foo.vim (from within Vim) vim -S ~/foo.vim
start Vim with the foo.vim session.
Buffers # Vim buffer commands Command Explanation CTRL-ww
move between buffers
Tabs # Vim tab commands Command Explanation :tabs
list all tabs including their displayed windows :tabm 0
move current tab to first :tabm
move current tab to last :tabm {i}
move current tab to position i+1 :tabn
go to next tab :tabp
go to previous tab :tabfirst
go to first tab :tablast
go to last tab gt
go to next tab gT
go to previous tab {i}gt
go to tab in position i
Vim scroll lock commands Command Explanation CTRL-s
enable terminal scroll lock CTRL-q
disable 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 Command Explanation :q
quit Vim. Fails when changes have been made. :q!
quit without writing. :cq
quit always :wq
write 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 ZZ
write current file ZQ
quit current file and exit (same as ":q!").
NERDtree cheats # Basics # Basic NERDtree commands Command Explanation :NERDTreeToggle
show / hide file browser :NERDTreeFind
show current file in file browser q
close the NERDTree window A
zoom (maximize-minimize) the NERDTree window ?
toggle help
Navigation # NERDtree navigation commands Command Explanation P
go to root p
go to parent K
go to first child J
go to last child CTRL-j
go to next sibling CTRL-k
go to prev sibling
File system # NERDtree file system commands Command Explanation C
change tree root to the selected dir u
move tree root up a dir U
move tree root up a dir but leave old root open r
refresh cursor dir R
refresh current root m
how menu cd
change the current working directory to the selected dir
Filtering # NERDtree filtering commands Command Explanation I
hidden files f
file filters F
files B
bookmarks
Files # NERDtree commands to work on files Command Explanation o
open in prev window go
preview t
open in new tab T
open in new tab silently i
open split gi
preview split s
open vsplit gs
preview vsplit
Bookmarks # NERDtree bookmarking commands Command Explanation :Bookmark name
bookmark the current node as 'name' o
open bookmark t
open in new tab T
open in new tab silently D
delete bookmark
Directories # NERDtree commands to work on directories Command Explanation o
open & close node O
recursively open node x
close parent of node X
close all child nodes of current node recursively e
explore 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 Command Explanation ?
show the help dialog for a list of all available keys r
reload gs
view source i
enter insert mode -- all commands will be ignored until you hit Esc to exit yy
copy the current url to the clipboard yf
copy a link url to the clipboard v
enter visual mode V
enter visual line mode
Navigating the current page # Vimium commands to navigate the current page. Command Explanation h
scroll left j
scroll down k
scroll up l
scroll right gg
scroll to top of the page G
scroll to bottom of the page d
scroll down half a page u
scroll up half a page gf
cycle forward to the next frame gF
focus the main/top frame ]], [[
Follow the link labeled 'next' or '> gu
go up one level in the URL hierarchy gU
go up to root of the URL hierarchy ge
edit the current URL zH
scroll all the way left zL
scroll all the way right
Navigating to new pages # Vimium commands to navigate to new pages. Command Explanation f
open a link in the current tab F
open a link in a new tab o
Open URL O
Open URL b
Open bookmark B
Open bookmark in a new tab <a-f>
open multiple links in a new tab gE
edit the current URL and open in a new tab
Finding # Vimium commands to find contents. Command Explanation /
enter find mode n
cycle forward to the next find match N
cycle 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. Command Explanation J, gT
go one tab left K, gt
go one tab right g0
go to the first tab. Use ng0 to go to n-th tab g$
go to the last tab ^
visit the previously-visited tab t
create tab yt
duplicate current tab x
close current tab X
restore closed tab (i.e. unwind the 'x' command) T
search through your open tabs W
move 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:
Tags Author 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: https://www.j15k.com/ License 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="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://www.ditig.com/publications/vim-cheat-sheet">Vim cheat sheet</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://www.j15k.com/">Jonas Jared Jacek</a> is licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-NC-SA 4.0</a>.</p>
For more information see the DITig legal page .
“Obey standards unless you've a darn good reason.”
Alan Cooper , Software designer and programmer About Face , 1995 - IT quotes