Getting Started

Macros

- -
qi Record macro i
q Stop recording macro
@i Run macro i
7@i Run macro i 7 times
@@ Repeat last macro
You can save macro for any letters not just i

Visual mode

Shortcut Description
v Enter visual mode
V Enter visual line mode
<C-v> Enter visual block mode
ggVG Select all text
> / < Shift text right/left

Repeating

Shortcut Description
. Repeat last command
; Repeat latest f, t, F or T
, Repeat latest f, t, F or T reversed
& Repeat last :s
@: Repeat a command-line command

Cut and paste

Shortcut Description
x Delete character (Cut)
p / P Paste after/before
xp Swap two characters
D Delete to end of line (Cut)
dw Delete word (Cut)
dd Delete line (Cut)
ddp Swap two lines
yy Yank line (Copy)
"*p * * "+p
"*y * * "+y

#In visual mode

Shortcut Description
d * * x
s Replace selection
y Yank selection (Copy)

Normal Mode

Shortcut Description
r Replace one character
R Enter Replace mode
u / 3u Undo changes 1 / 3 times
U Undo changes on one line
J Join with next line
<C-r> / 5 <C-r> Redo changes 1 / 5 times

Saving and Exiting

Shortcut Description
:w Save
:q Close file
:wq * * :x *
:wqa Save and quit all files
:q! * * ZQ
:qa Close all files
:qa! Force quit all files
:w now.txt Write to now.txt
:sav new.txt Save and edit new.txt
:w !sudo tee % Write to readonly file

Insert Mode

Shortcut Description
i / a Insert before/after cursor
I / A Insert start/end of line
o / O (letter) Insert new line below/above
s / S Delete char/line and insert
C / cc Change to end of/current line
gi Insert at last insert point
Esc * * <C-[>

Motions

Shortcut Description
h * * j *
<C-u> / <C-d> Half-page up/down
<C-b> / <C-f> Page up/down

#Words

Shortcut Description
b / w Previous/Next word
ge / e Previous/Next end of word

#Line

Shortcut Description
0 (zero) / $ Start/End of line
^ Start of line (non-blank)

#Character

Shortcut Description
Fe / fe Move to previous/next e
To / to Move before/after previous/next o
| / n| Go to first/nth column

#Document

Shortcut Description
gg / G First/Last line
:n * * nG
} / { Next/Previous empty line

#Window

Shortcut Description
H / M / L Top/Middle/Bottom screen
zt / zz / zb Top/Center/Bottom this line

Motion Diagrams

▼/▶ Cursor   ▽/▷ Target

#Left-right motions

┌───────────── |      
├───────────── 0      $ ──────────────┐ 
│  ┌────────── ^      fe ────────┐    │
│  │  ┌─────── Fo     te ───────┐│    │
│  │  │┌────── To     30| ───┐  ││    │
│  │  ││ ┌──── ge     w ───┐ │  ││    │
│  │  ││ │ ┌── b      e ─┐ │ │  ││    │
│  │  ││ │ │  ┌h      l┐ │ │ │  ││    │
▽  ▽  ▽▽ ▽ ▽  ▽▼      ▼▽ ▽ ▽ ▽  ▽▽    ▽
   echo "A cheatsheet from quickref.me"

#Up-down motions

                 - SCREEN 1 START
   ┌─┬─────────▷ #!/usr/bin/python
   │ │     ┌───▷     
   │ │     │     print("Hello")
   │ │     { } ▶ print("Vim")
   │ │       │   print("!")
   │ │       └─▷    
   │ │ ┌───┬───▷ print("Welcome")
G gg H M L k j ▶ print("to")
│        │   └─▷ print("quickref.me")
│        │       print("/vim")
│        │     
│        └─────▷ 
│                - SCREEN 1 END
└──────────────▷ print("SCREEN 2")
Comments