Table of Contents

PC Software

vi / vim Cheat Sheet



Web Site

List of vi/vim Commands

Invocation

Operation Action supplement
vi FILE Open the FILE for editing. If it does not exist, a new file is created.
view FILE
vi -R FILE
view is a read only version of vi.
vi +n FILE Open the FILE with the cursor positioned at the given line. vi +5 httpd.conf
vi +/STRING/ FILE Open the FILE with the cursor positioned at the first line containing the string.
vi -r FILE Opens a recovery copy of the FILE.

Saving and Quitting

Operation Action supplement
:w to write to the file.
:q Quits, but only if no changes have been made.
:q! Quits without saving, regardless of any changes.
:wq
ZZ
Saves and quits.
:w NEWFILE

Insert Text

Operation Action supplement
i Insert at cursor
a Insert after cursor
Esc

Delete

Operation Action supplement
x Delete character
dd Delete line 2dd ← Delete 2 lines
dw Delete word
d$ Delete to end of line

Copy

Operation Action supplement
yy Copy a line
yw Copy a word
y$ Copy from cursor to end of line

Mark

Operation Action supplement
v
Shift + v
Ctrl + v

Undo & Redo

Operation Action supplement
u Undo
Ctrl + r Redo

Moving Around

Operation Action supplement
k Go up 5k
j Go down
h Go left
l Go right
0
Home
Moves to the start of the current line.
$
End
Go to end of line
^ Go to beginning of non-whitespace part of line
gg Go to beginning of file
G Go to end of file

expert

Operation Action supplement
Ctrl + b Move backwards one page.
Ctrl + f Move forwards one page.
Ctrl + u Move backwards by half a page.
Ctrl + d Move forwards by half a page.
w Moves to the start of the next word
e Moves to the end of the current word
% Moves the cursor to the matching bracket, any of (), [] or {}.
H Moves to the line at the top of the screen.
L Moves to the line at the bottom of the screen.
Operation Action supplement
/WORD Search STRINGS (forward) \ = Escape
?WORD Search STRINGS (backward) \ = Escape
n Find next
N Find previous
:noh
:nohlsearch
Turn off highlighting (after a search)

Substitutions

Operation Action supplement
:%s/BEFORE/AFTER/g
s : substitude
c : check
substitution delete linefeed code
:%s/^M//g ← ^M = Ctrl-v Ctrl-m
:%s/tmp-db1/tmp-aaa1/gc
:%s;/home/user01/;/var/www/;g


set command

Operation Action supplement
:set paste Paste Mode
:set noautoindent
:set autoindent
:set noai
:set ai
Disable/Enable autoindent


Tips

Operation Action supplement
Ctrl + v
move go to end line
Shit + i
# or //
esc
Multiple Comment


References