Cheat sheets /

Vim cheat sheet

Enough Vim to be fast, not just to escape: the motions and edits worth learning, search and replace, splits, and recording a macro.

Download all 38 for Snippet Keeper Get Snippet Keeper

In Snippet Keeper, click Import at the bottom of the sidebar and choose the file. They land in your vim app, and ones you already have are skipped. The highlighted parts become fill-in fields: type a value (or pick one), and the finished command is on your clipboard.

Moving

Next or previous word

w / b

Start or end of line

0 / $

First non-blank character

^

Top or bottom of the file

gg / G

Go to a line

lineG

Matching bracket

%

Half a page down or up

Ctrl-d / Ctrl-u

Next occurrence of the word under the cursor

*

Editing

Insert before or after the cursor

i / a

Insert at the end of the line

A

New line below or above

o / O

Change a word

ciw

Change inside quotes

ci"

Delete a line

dd

Delete to the end of the line

D

Copy a line

yy

Paste after the cursor

p

Undo or redo

u / Ctrl-r

Repeat the last change

.

Indent or outdent a line

>> / <<

Join the next line onto this one

J

Search and replace

Search forward

/pattern

Next or previous match

n / N

Replace everywhere

:%s/find/replace/g

Replace everywhere, asking each time

:%s/find/replace/gc

Clear search highlighting

:noh

Visual mode

Select characters, lines or a block

v / V / Ctrl-v

Reselect the last selection

gv

Files and splits

Save

:w

Save and quit

:wq

Quit without saving

:q!

Open a file

:e file

Open a file in a split

:split file

Move between splits

Ctrl-w w

Save a file you opened without sudo

:w !sudo tee % > /dev/null

Macros

Record a macro

Press q again to stop recording.

qregister

Play a macro

@register

Play a macro many times

count@register

Keep these one keystroke away.

Snippet Keeper is a Mac app for the commands you keep looking up. Press ⌥⇧Space in any app, type a few letters, fill in the blanks, and it’s on your clipboard.

Snippet Keeper asking for the values in a kubectl command before copying it