Skip to content

Vim Cheat Sheet

Global

:ter[minal] Open a terminal window
u Undo
Ctrl + r Redo

Quitting

:x or :wq Exit, saving changes
:w Writing to a file, not quiting
:q Exit, if there is no changes
ZZ Exit and save changes if any
:q! Exit without saving any changes

Inserting

i Inserting before cursor
I Inserting before line
a Append after cursor
A Append after line
o Open a new line after current line
O Open a new line before current line
r Replace single character
R Replace many character

Deleting

x Delete character at the cursor
X Delete character before the cursor
D Delete from cursor to the end of the line
dd or :d Delete current line

Changing Text

guu Lowercase line
gUU Uppercase line
~ Toggle uppercase and lowercase

Ranges

:n,m Range - line n to m
:. Range - current line
:$ Range - last line
:% Range all lines
:g/{pattern} Range all files that mathces pattern
:g!/{pattern} Range all files that doesn't mathces pattern

Visual Mode

v Start the visual mode, then we can do a command like yank
V Start a linewise visual mode
Ctrl + v Start visual block mode
o Move to other end of marked area (top to bottom)
O Move to the corner of the block (right)
aw Mark a word
ab or a( Block with ()
aB or a{ Block with {}
at Block with <>
ib or i( Inner block with ()
iB or i{ Inner block with {}
it Inner block with <>
y Yank(copy) marked text
d Delete marked text
~ Toggle case for marked text
> Shift text right / Tab
< Shift text left / Shift+Tab
= Autoindent marked text
Esc Exit visual mode

Indent text

>> Move right
<< Move left
>% Indent block with cursor {} ()
<% Deindent block with cursor {} ()
]p Paste and indent block
=% Reindent block with cursor {} ()

Cut and Paste

yy or Y Yank(copy) a line
p Paste after cursor
P Paste before cursor
dd Delete a line
D Delete to the end of the line
x Cut character
:1,6d Delete lines 1 to 6
:.,$d From current line to end
:g/{pattern}/d Delete lines with pattern
:g!/{pattern}/d Delete lines without pattern

Searching

/{pattern} Search forward for the pattern string
?{pattern} Search backward for the pattern string
n Next instance of the string
N Previous instance of the string

Replacing

:s/{pattern}/{replace}/flags Replace all occurence of 'pattern' with 'replace' on a single line
:%s/article/tutorial/flags Replace all occurence 'pattern' with 'replace' on a every line of file
g Flag - Replace all occurence
c Flag - Confirm replaces

Working with multiple files

:NERDTree File system explorer for the Vim editor (need to install manually, see vim customization blog)
:FZF Search among the files in the project (need to install manually, see vim customization blog)
Ctrl + ww To switch between windows
Ctrl + wh To go to left windows
Ctrl + wl To go to right windows
:bn[ext] Go to next buffer
:bp[revious] Go to previous buffer
:bd[elete] Delete buffer / Close files
:b# Go to buffer by index
:ls List all open buffers
:sp[lit] {filename} Open the file in horizontal split
:vs[plit] {filename} Open the file in vertical split
:tab ba Edit all buffers as vertical
gt Go to next buffer
{n}gt Go to n index buffer
Ctrl + ws Split windows
Ctrl + wq Quit window