Vi Or Vim Editor Cheat Sheet

ADVERTISEMENT

VI or VIM EDITOR CHEAT SHEET
There are two different modes of operation within vi: the command mode and the insert mode.
The following commands are issued while in the command mode.
The insert mode will insert whatever text you type into the current file (see Inserting Text section below).
To return to command mode from insert mode, hit the ESCape key.
(Note: This is always a safe thing to do.)
Editor commands preceded by ‘:’, ‘/’, or ‘?’ will appear in the lower left hand corner of the screen. Other
commands will not appear on the screen.
A SENTENCE is defined to end at a ‘.’, ‘!’, or a ‘?’ which is followed by either the end of the line or two
spaces. A PARAGRAPH is defined to begin after each empty line.
CRUISING AROUND
DELETING TEXT
↑ or k
move cursor up
x
delete current character
↓ or j
move cursor down
nx
delete next <n> characters
→ or l
move cursor right
dw
delete current word
← or h move cursor left
dd
delete current line
move cursor to next line
ndd
delete next <n> lines
+
move cursor to previous line
D
delete to end of line
-
go to matching parenthesis or bracket
dG
delete from current line to bottom
%
go to the beginning of line
0 or ^
go to end of line
IN SEARCH OF TEXT
$
go to column <n>
/string
search forward for <string>
n|
skip forward one word
?string
search backward for <string>
w
skip backward one word
n
repeat last search command
b
go to end of current word
:n,m s/str1/str2/g
search from line <n> to line <m> for <str1>
e
skip to next sentence
and replace with <str2>
)
skip to previous sentence
:1,$ s/str1/str2/g
search and replace all occurences of <str1>
(
skip to next paragraph
with <str2>
}
skip to previous paragraph
{
go to line <n>
CUTTING AND PASTING
nG
go to bottom
yw
yank a copy of the current word
G
yb
yank a copy of the previous word
Y
yank a copy of current line
nY
yank a copy of the next <n> lines
INSERTING TEXT
append after cursor
p
put last yanked or deleted or changed text after cursor
a
append after end of line
P
put last yanked or deleted or changed text before cursor
A
insert before cursor
i
insert at beginning of line
FIXING GOOFS
I
open new line below current line
u
undo last change
o
open new line above current line
U
restore current line
O
:e!
re-edit current file without saving changes
CHANGING TEXT
replace single character with <x>
FILE MANIPULATION
rx
replace with <text>
:x or :wq
quit and save changes
Rtext
join next line with current line
:q!
quit without saving changes
J
cwtext change word to <text>
:w name
write entire file to <name>
repeat last command (text change, delete, etc.)
:w name
write (save) changes
.
For a more detailed reference refer to:

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go