Cheat Sheet: The Vim Linux Command Line Editor Cheat Sheet

Akshata Shanbhag 11-01-2020

Powerful, efficient, and highly configurable—that’s Vim in a nutshell for you. This cross-platform command line text editor has been around for ages and has a solid online community you can look to for help. The best part is that Vim is free and open source.


If you have only dabbled in Vim until now, the next step is getting comfortable with Vim commands i.e. Vim’s keyboard shortcuts. (This is essential given that Vim is a keyboard-centric text editor.)

We’ve even compiled the best Vim shortcuts into a cheat sheet for you! Scroll down to discover it. You can also download a PDF version of this Vim cheat sheet and save it to your desktop for quick access.

Keep in mind that Vim (Vi Improved) is a modified clone of the Unix-based text editor Vi, which ships with several Linux distros. So you’ll find that several Vim commands also function as Vi commands.

FREE DOWNLOAD: This cheat sheet is available as a downloadable PDF from our distribution partner, TradePub. You will have to complete a short form to access it for the first time only. Download The Vim Cheat Sheet.

The Vim Commands Cheat Sheet

Cursor Movement
hMove cursor left
jMove cursor down
kMove cursor up
lMove cursor right
w OR ¹WMove cursor to the start of the next word
b OR ¹BMove cursor to the start of the previous word
e OR ¹EMove forward to the end of a word
0Move to the start of the line
^Move to the first non-blank character of the line
$Move to the end of the line
GGo to the last line of the document
nG OR :nGo to line number n
'To the position before the latest jump, / where the last "m'" / "m`" command was given.
fxMove to next occurrence of character x
txMove to one character before the character x
}Move to next paragraph
{Move to previous paragraph
HMove to home (top) of screen
LMove to last line of screen
MMove to middle of screen
3, f, xMove to 3rd instance of character x forward from cursor on current line.
3, F, xMove to 3rd instance of character x back from cursor on current line.
Editing a File
rReplace a single character
ddCut (delete) a line
yyYank (copy) a line
2yyYank (copy) two lines
JJoin line below to the current one
cc OR SChange (replace) entire line
cwChange (replace) to the end of the word
c$Change (replace) to the end of the line
sDelete character and substitute text
xpTranspose two letters (delete and paste)
Ctrl rRedo
.Repeat last command
Search and Replace
*Search for word under cursor
/patternSearch for pattern
?patternSearch backward for pattern
nRepeat search in same direction
NRepeat search in opposite direction
:%s/old/new/gReplace all instances of old with new
:%s/old/new/gcReplace all instances of old with new, with confirmations
Screen Movement
Ctrl uMove screen up by half page
Ctrl bMove screen up by one page
Ctrl dMove screen down by half page
Ctrl fMove screen down by one page
zzCenter screen on cursor
ztAlign top of screen with cursor
zbAlign bottom of screen with cursor
Insert Mode (Insert Text)
iEnter insert mode
IInsert at the beginning of the line
aInsert (append) after the cursor
AInsert (append) at the end of the line
oAppend (open) a new line below the current line
OAppend (open) a new line above the current line
eaInsert (append) at the end of the word
EscExit insert mode
Change Case
~Toggle case (Case => cASE)
gUUUppercase current line (also gUgU)
guuLowercase current line (also gugu)
Visual Mode (Mark Text)
vStart visual mode, mark lines, then do a command (like y-yank)
VStart linewise visual mode
voMove to other end of marked area
Ctrl vStart visual block mode
vOMove to other corner of block
vawMark a word
vabMark a block with ()
vaBMark a block with {}
vibMark inner block with ()
viBMark inner block with {}
EscExit visual mode
Visual Commands
>Shift text right
Shift text left
#ERROR!Auto-indent current line
Shift current line left by shiftwidth
>>Shift current line right by shiftwidth
yYank (copy) marked text
dDelete marked text
~Switch case
Folding Commands
zf#jCreate a fold from the cursor down # lines
zf/String creates a fold from the cursor to string
zjMove the cursor to the next fold
zkMove the cursor to the previous fold
zaToggle a fold under cursor
zoOpen a fold at the cursor
zOOpen all folds at the cursor
zcClose a fold under cursor
zmIncrease the foldlevel by one
zMClose all open folds
zrDecrease the foldlevel by one
zRDecrease the foldlevel to zero—all folds will be open
zdDelete the fold at the cursor
zEDelete all folds
[zMove to start of open fold
]zMove to end of open fold
#gtMove to tab number #
Ctrl w, tMove the current split window into its own tab
:tabmove #Move current tab to the #th position (indexed from 0)
:tabnew filename/ :tabn filenameOpen a file in a new tab
:tabclose / :tabcClose the current tab and all its windows
:tabonly / :taboClose all tabs except the current one
gt / :tabnext / :tabnMove to the next tab
gT / :tabprev / :tabpMove to the previous tab
Working With Multiple Files
:e filenameEdit a file in a new buffer
:eneOpen a blank file for editing
:bnext / :bnGo to the next buffer
:bprev / :bpGo to the previous buffer
:bdDelete a buffer (close a file)
:sp filenameOpen a file in a new buffer and split window
:vs filenameOpen a file in a new buffer and vertically split window
Ctrl w, sSplit window
Ctrl w, wSwitch windows
Ctrl w, qQuit a window
Ctrl w, vSplit window vertically
Ctrl w, hMove cursor to window left
Ctrl w, lMove cursor to window right
Ctrl w, kMove cursor to window above
Ctrl w, jMove cursor to window below
Ctrl w, rRotate windows clockwise
Ctrl w, TMove current window to a new tab
:onClose all windows except current window
Ctrl w, |Maximize width of active window
Ctrl w, 1, |Minimize width of active window
Ctrl w, _Maximize height of active window
Ctrl w, 1, _Minimize height of active window
Ctrl w, =Equalize the size of windows
Exiting a File
:wWrite (save) the file, but don't exit
:wqWrite (save) and quit
:x OR ZZWrite (save) current file if modified and quit
:qQuit (fails if there are unsaved changes)
:q!Quit and discard unsaved changes
:qaQuit all buffers and windows
ZQQuit without checking for changes
¹Word can contain punctuation.

Vim Improved

Vim is no doubt a great text editor, but it could do with a few of the useful features that most modern text editors are equipped with. The good news is that you can add top features from other text editors to Vim How to Add Top Features From Other Text Editors to Vim Using the Vim text editor but wishing it was as functional as other text editors? Here's how to install new features in Vim. Read More !

Image Credit: Markus Spiske on Unsplash

Related topics: Cheat Sheet, Vim.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. dragonmouth
    January 11, 2020 at 8:08 pm

    "Powerful, efficient, and highly configurable"
    Also byzantine and nonintuive. A fossil from the early days of UNIX.