VI Cheat Sheet
VI Cheat Sheet
EXINIT environment variable containing vi Sets right margin to x, automatic word wrap
commands to be executed upon startup
Deleting, Copying, and Pasting Text Searches and Substitution (cont.)
Deleting Text x delete character at cursor Special Characters [ccc] matches any specified character
dd delete line [^ccc] matches any character except those
ndd delete n lines specified
ndw delete n words [c1-c2] matches any character in range
d$ delete to end of line ^ matches beginning of line
d^ delete to beginning of line $ matches end of line
dG delete to end of file . matches any one character
d1G delete to beginning of file * matches zero or more occurrences of
previous character
Copying Text yy yank current line into buffer
.* matches any number of characters
nyy yank n lines into buffer
yw yank word Case Sensitivity :set ignorecase
nyw yank n words disable case sensitivity
:set noic enable case sensitivity
Pasting Text p put most recently deleted or yanked
characters or words after cursor; put lines
below current line
Miscellaneous Commands
P put most recently deleted or yanked
characters or words before cursor; put Shell Commands :!command execute command
lines above current line :sh invoke subshell; use the exit command
to return to vi
:r !command insert output of command below current
Searches and Substitution line
Undoing Commands u undo last change
Simple Searches /string search forward for string U undo recent changes made to current line
?string search backward for string
n repeat search Repeating Com- . repeat last command that made an
N repeat search in opposite direction mands editing change
Global Search :g/string/command Reading in Files :r filename insert filename below current line
execute command on lines containing
string Joining Lines J join next line to current line
:v/string/command Line Numbers Ctrl-g display current line number and number
execute command on lines not containing of lines in file
string
:set number display line numbers
Substitution :x,ys/oldstring/newstring/flags :set nonumber remove displayed line numbers
Substitutes newstring for oldstring in line range x,y. Screen Refresh Ctrl-l refresh screen
flags (optional):
c wait for confirmation (y or n)
g replace all occurrences within specified
lines (default is to replace only first
occurrence)
Range specifiers:
. current line
$ last line
% entire file