Helper-KitCheatsheets

Vim Cheatsheet

Vim 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

Save & quit

Save

Write the file.

:w

Save and quit

:x only writes if something changed. ZZ does the same.

:wq
:x
ZZ

Quit

Quit if there are no unsaved changes.

:q

Quit without saving

Careful

Throw away your changes and quit.

:q!

Save as

Write to a new file name.

:w newname.txt

Save a protected file

Save with sudo when you opened a file without permission.

:w !sudo tee %

Modes

Insert before / after cursor

Start typing at the cursor, or just after it.

i
a

Insert at start / end of line

Jump to the start or end of the line and start typing.

I
A

New line below / above

Open a new line and start typing.

o
O

Back to Normal mode

Leave Insert or Visual mode. Ctrl+[ works too.

Esc

Command-line mode

Type a command like :w, then Enter.

:

Replace mode

Type over existing text.

R

Move

Left, down, up, right

The arrow keys also work.

h  j  k  l

Word by word

Next word start, previous word start, end of word.

w  b  e

W, B, E treat punctuation as part of the word.

Start / end of line

0 = first column, ^ = first non-blank character, $ = end.

0  ^  $

Top / bottom of file

First line, last line.

gg
G

Go to a line

Jump to line 42.

:42
42G

Scroll by page

Half page down/up, full page down/up.

Ctrl+d  Ctrl+u
Ctrl+f  Ctrl+b

Find a character in the line

Jump to the next x, or just before it. ; repeats.

fx  tx  ;  ,

Matching bracket

Jump between ( ), [ ], { }.

%

Jump back / forward

Return to where you were before a jump.

Ctrl+o
Ctrl+i

Centre the screen

Scroll so the cursor line is in the middle.

zz

Edit

Delete character

Delete the character under the cursor.

x

Delete word

Delete from the cursor to the start of the next word.

dw

Delete line

Delete the whole line, or 3 lines.

dd
3dd

Delete to end of line

Same as d$.

D

Change word / line

Delete and start typing.

cw
cc
C

Replace one character

Replace the character under the cursor with x.

rx

Join lines

Join the next line onto this one.

J

Indent / unindent

Shift the line right or left.

>>
<<

Toggle case

Switch upper/lower case of the character.

~

Text objects

Change inside word

Replace the whole word under the cursor, wherever the cursor is in it.

ciw

Inside quotes / brackets

Change the text inside "…", (…) or {…}.

ci"
ci(
ci{

Around (including the brackets)

Delete the brackets or quotes too.

da"
da(

Inside an HTML tag

Change the text between <tag> and </tag>.

cit

Paragraph

Delete or copy the current paragraph.

dap
yap

Copy & paste

Copy (yank) line

Copy the whole line.

yy

Copy word

Copy to the start of the next word.

yw
yiw

Paste

After the cursor, or before it.

p
P

Use the system clipboard

Copy to or paste from the system clipboard.

"+yy
"+p

Needs a Vim built with clipboard support (vim --version shows +clipboard).

Cut

Deleting also copies, so dd then p moves a line.

dd  p

Visual mode

Select characters / lines / block

Start a selection, then move to extend it.

v
V
Ctrl+v

Act on the selection

Copy, delete, change, indent.

y  d  c  >  <

Select everything

Go to the top, select by line to the bottom.

ggVG

Re-select

Select the last selection again.

gv

Type on many lines

Select a column with Ctrl+v, press I, type, then Esc.

Ctrl+v  j j  I  text  Esc

Search forward / backward

Type the text and press Enter.

/text
?text

Next / previous match

Repeat the last search.

n
N

Search for the word under the cursor

Forward or backward.

*
#

Replace in the current line

First match, or every match with g.

:s/old/new/
:s/old/new/g

Replace in the whole file

Every match. Add c to confirm each one.

:%s/old/new/g
:%s/old/new/gc

Replace in selected lines

Select with V first; Vim fills in the range.

:'<,'>s/old/new/g

Ignore case / clear highlight

Case-insensitive search, and hide match highlighting.

/text\c
:noh

Undo & repeat

Undo / redo

Undo the last change, or redo it.

u
Ctrl+r

Repeat last change

Do the last edit again.

.

Counts

Put a number before a command to repeat it.

5j
3dw
10x

Files, splits & tabs

Open a file

Edit another file. Tab completes file names.

:e path/to/file

File browser

Browse the current folder.

:Explore

Buffers

List open files, go to next/previous, switch by number.

:ls
:bn  :bp
:b 2

Split the window

Horizontal or vertical split.

:split file
:vsplit file

Move between splits

Ctrl+w then a direction key, or w to cycle.

Ctrl+w h/j/k/l
Ctrl+w w

Tabs

Open a tab, next tab, previous tab.

:tabnew file
gt
gT

Settings

Line numbers

Show line numbers, or numbers relative to the cursor.

:set number
:set relativenumber

Spaces instead of tabs

Indent with 2 spaces.

:set expandtab tabstop=2 shiftwidth=2

Search settings

Highlight matches, search while typing, smart case.

:set hlsearch incsearch ignorecase smartcase

Turn a setting off

Prefix it with no.

:set nonumber

Make settings permanent

Put the set lines (without :) in ~/.vimrc.

set number
set expandtab tabstop=2 shiftwidth=2
syntax on

Paste without auto-indent

Stops pasted code from getting extra indentation.

:set paste
:set nopaste

Marks & macros

Set and jump to a mark

Mark a spot as a, then jump back to it.

ma
`a

Record a macro

Record into register q, do the edits, stop with q.

qq  …edits…  q

Play a macro

Run it once, 10 times, or repeat the last one.

@q
10@q
@@

Get help

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.

About This Cheatsheet

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.

Quick Tips

  • Stuck? Press Esc, then type :q! and Enter to quit without saving.
  • Combine an action with a motion: d (delete) + w (word) = dw, c (change) + iw (inner word) = ciw.
  • Put a number in front of a command to repeat it: 5j moves down 5 lines.
  • Press . to repeat your last change, often the fastest way to make the same edit again.
  • Save your favourite settings in ~/.vimrc so they apply every time.

Frequently Asked Questions

How do I quit Vim?

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.

Why can't I type?

Vim starts in Normal mode, where keys are commands. Press i to start typing, and Esc to go back to Normal mode.

How do I copy and paste?

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.

What is the difference between Vim and Vi?

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.

Was this tool helpful?

More in this category