Save
Write the file.
:wVim commands and shortcuts: save and quit, move, edit, text objects, visual mode, search and replace, splits and macros.
Vim Cheatsheet · Helper-Kit
Commands run in Normal mode unless a card says otherwise. Press Esc to get back to Normal mode. Keys are case-sensitive.
72 entries
Write the file.
:w:x only writes if something changed. ZZ does the same.
:wq
:x
ZZQuit if there are no unsaved changes.
:qThrow away your changes and quit.
:q!Write to a new file name.
:w newname.txtSave with sudo when you opened a file without permission.
:w !sudo tee %Start typing at the cursor, or just after it.
i
aJump to the start or end of the line and start typing.
I
AOpen a new line and start typing.
o
OLeave Insert or Visual mode. Ctrl+[ works too.
EscType a command like :w, then Enter.
:Type over existing text.
RThe arrow keys also work.
h j k lNext word start, previous word start, end of word.
w b eW, B, E treat punctuation as part of the word.
0 = first column, ^ = first non-blank character, $ = end.
0 ^ $First line, last line.
gg
GJump to line 42.
:42
42GHalf page down/up, full page down/up.
Ctrl+d Ctrl+u
Ctrl+f Ctrl+bJump to the next x, or just before it. ; repeats.
fx tx ; ,Jump between ( ), [ ], { }.
%Return to where you were before a jump.
Ctrl+o
Ctrl+iScroll so the cursor line is in the middle.
zzDelete the character under the cursor.
xDelete from the cursor to the start of the next word.
dwDelete the whole line, or 3 lines.
dd
3ddSame as d$.
DDelete and start typing.
cw
cc
CReplace the character under the cursor with x.
rxJoin the next line onto this one.
JShift the line right or left.
>>
<<Switch upper/lower case of the character.
~Replace the whole word under the cursor, wherever the cursor is in it.
ciwChange the text inside "…", (…) or {…}.
ci"
ci(
ci{Delete the brackets or quotes too.
da"
da(Change the text between <tag> and </tag>.
citDelete or copy the current paragraph.
dap
yapCopy the whole line.
yyCopy to the start of the next word.
yw
yiwAfter the cursor, or before it.
p
PCopy to or paste from the system clipboard.
"+yy
"+pNeeds a Vim built with clipboard support (vim --version shows +clipboard).
Deleting also copies, so dd then p moves a line.
dd pStart a selection, then move to extend it.
v
V
Ctrl+vCopy, delete, change, indent.
y d c > <Go to the top, select by line to the bottom.
ggVGSelect the last selection again.
gvSelect a column with Ctrl+v, press I, type, then Esc.
Ctrl+v j j I text EscType the text and press Enter.
/text
?textRepeat the last search.
n
NForward or backward.
*
#First match, or every match with g.
:s/old/new/
:s/old/new/gEvery match. Add c to confirm each one.
:%s/old/new/g
:%s/old/new/gcSelect with V first; Vim fills in the range.
:'<,'>s/old/new/gCase-insensitive search, and hide match highlighting.
/text\c
:nohUndo the last change, or redo it.
u
Ctrl+rDo the last edit again.
.Put a number before a command to repeat it.
5j
3dw
10xEdit another file. Tab completes file names.
:e path/to/fileBrowse the current folder.
:ExploreList open files, go to next/previous, switch by number.
:ls
:bn :bp
:b 2Horizontal or vertical split.
:split file
:vsplit fileCtrl+w then a direction key, or w to cycle.
Ctrl+w h/j/k/l
Ctrl+w wOpen a tab, next tab, previous tab.
:tabnew file
gt
gTShow line numbers, or numbers relative to the cursor.
:set number
:set relativenumberIndent with 2 spaces.
:set expandtab tabstop=2 shiftwidth=2Highlight matches, search while typing, smart case.
:set hlsearch incsearch ignorecase smartcasePrefix it with no.
:set nonumberPut the set lines (without :) in ~/.vimrc.
set number
set expandtab tabstop=2 shiftwidth=2
syntax onStops pasted code from getting extra indentation.
:set paste
:set nopasteMark a spot as a, then jump back to it.
ma
`aRecord into register q, do the edits, stop with q.
qq …edits… qRun it once, 10 times, or repeat the last one.
@q
10@q
@@Open Vim’s built-in help, or the tutorial from the terminal.
:help
:help dd
vimtutor💡 Search matches titles, descriptions and the commands themselves. Copy puts the exact text on your clipboard; Print gives a clean sheet without menus or buttons. Searching happens in your browser; nothing is sent anywhere.
Vim is a keyboard-driven text editor found on almost every Linux server, and it often opens when Git asks for a commit message. This cheatsheet covers saving and quitting, the modes, moving around, editing, text objects, copying and pasting, visual mode, search and replace, undo and repeat, files, splits and tabs, settings, marks and macros. Commands run in Normal mode unless a card says otherwise; press Esc to get back to it. Commands that start with : are typed at the bottom of the screen and run with Enter. New to Vim? Learn the save and quit commands first, then the movement keys. Running vimtutor in a terminal gives you a 30-minute interactive lesson.
Press Esc to make sure you are in Normal mode, then type :q and press Enter. Use :wq to save and quit, or :q! to quit without saving.
Vim starts in Normal mode, where keys are commands. Press i to start typing, and Esc to go back to Normal mode.
yy copies a line and p pastes it below. In Visual mode (v), select text and press y to copy. Use "+y and "+p to work with the system clipboard.
Vim ("Vi improved") is a newer version of Vi with unlimited undo, syntax highlighting, visual mode, splits and plugins. On most systems the vi command actually runs Vim.