VI - Cheat - Sheet Onepager

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

VI

^ ESC: escape from edit


<- | | -> to command mode
ˇ
H J K L

Insert:
i insert in place of cursor
a append after cursor
A append end of line
o new line below cursor
O new line above cursor

Delete:
x del single char on cursor
X del backwards a char (backspace)
3x del 3 chars forward
dw del word
3dw del 3 words
dd del current line
3dd del 3 lines (inc. current)
dG del up to start of file
d1G del down to end of file
"x2dd del 2 lines to name "x"
:x,yd del from line x to y
cc rewrite whole line
C rewrite to end of the line
:r <file> inser file under current line

Move:
f forward a char
F backward a char
w next word
b start of word
e end of word
( back a sentence
) forward a sentence
% move to matching bracket
0 move to start of line
$ move to end of line
H move to start of screen
M move to middle of screen
L move to end of screen
G move to end of file
1G move to start of file
nG move to n.th line
:/pattern/d Find line cont. pattern & del
Ctrl+g show line number
Ctrl+f scroll forward a page
Ctrl+b scroll backward a page

Search and replace:


/ search forward
? search backward
n go to next match
N go to prev. match
:s/from_pattern/to_string/g|c|&
g:whole line, c:confirm, &:repeat last
:%s/from_pattern/to_string/ whole file
Yank:
y yank (copy)
Y yank (copy) line (or yy)
y$ yank to end of line
y0 yank to start of line
y/swordfish yank to word swordfish
yfg yank to char g
5,10y yank from line 5 to 10
"xy3w yank 3 words from cursor to name "x"
"xy3f yank 3 chars from cursor to name "x"
:/dog/,/cat/d Find line cont. "dog" and
delete until line containing "cat"
:.,/foo/d Delete from current line to line
containing "foo"
p paste after cursor
P paste before cursor
"xp paste clipboard x after cursor

Misc:
u undo last change
U undo changes to line
J join lines
nJ join next n lines
. repeat last command

Commands:
:q quit (if there were no changes)
:q! quit without changes
:w save
:wq save and wuit
:set ic = ignore case
:set noic = case sensitive
:set nu set line numbers
:set nonu unset line numbers

You might also like