Read a File Using vi
vi filename Edit file
vi + filename Start at last line
vi +n filename Start at line n
vi -R filename Read only mode
Word Commands
w Next word
b Back word
e End of word
( Beginning of sentence
) End of sentence
} Beginning of paragraph
{ End of paragraph
Basic Cursor movement
k up
h l left right
j down
Arrow keys may also be used
CR Down one line to first non-blank
0 Beginning of line
$ End of line
Screen Control -- NOTE: CNTL followed by a letter signifies a control-key sequence.
CNTL-b Scroll back a whole page
CNTL-f Scroll forward a whole page
CNTL-u Scroll up a half page
CNTL-d Scroll down a half page
CNTL-e Scroll up one line
CNTL-y Scroll down one line
CNTL-l Refresh current screen (May be terminal dependent)
CNTL-g Display line number of current line
:set number Number lines
:set nonumber Remove line numbers
Inserting Text -- Commands are exited with the escape (ESC) character.
i Insert before cursor
I Insert at beginning of line
a Append after cursor
A Append at end of line
o Open lines after current line
O Open lines before current line
Changing Text -- Commands are exited with the escape (ESC) character.
C Change from cursor to end of line
s Substitute character
S Substitute line
cw Change word
r Replaces the current (no ESC necessary)
R Replaces from current cursor position to end of line; only changes typed-over characters
Delete Commands
x Delete character
dw Delete word
dd Delete line
D Delete from cursor to end of line
d Delete from cursor to beginning of line
u Undo command
U Restore entire line
Search Commands
/string Search for string below the current line
?string Reverse search for string
n Repeat last search
Control Commands
:w Write file
:w filename Writes to file filename
:w! filename Overwrites the file filename
:x,y w filename Write lines x through y to file filename
:wq Write file and quit
ZZ Write file and quit
:q Quit
:q! Quit and no changes are saved
:num Go to line number
:!command Execute command
:!!command Execute command and put output on current line
:e filename edits filename
:r filename places a copy of filename below current line
:r !command Execute command and put output below current line
Copy Commands
y Yanks current character
#y Yanks # characters from current character
yw Yanks current word
#yw Yanks # words from current word
yy Yanks current line
#yy Yanks # lines from current line
:x,y Yanks lines x thru y
p Places most recently yanked characters,words or lines after current character orline
P Places most recently yanked characters,words or lines before current character/line
:x mz Moves line x below line z
:x,y mz Moves lines x through y below line z
:xt z Copies line x below line z
:x,yt z Copies lines x through y below line z
J Joins the current line and the line below it
#J Joins # lines, beginning with the currentline