Summary of Unix VI Commands

VI Editor is one of the most powerful Screen-Oriented editor in Unix OS. VI Commands to do basic operations

i for “insert”
a for “append”
c for “change”
d for “delete”
p for “put”
y for “yank,”
Command to Save and Abandon Changes
                                                                          save changes     abandonchanges
Exit                                                               :wq                                       :q!
Do not exit                                         :w                                             :e!
Forcing changes
                                                                           saving changes
Exit                                                                :wq!
Do not exit                                           :w!
Cursor Movement
h –>left, one space.
j –>down, one line.
k –>up, one line.
l–>right, one space.
0–>Move to beginning of line.
$–>Move to end of line
0 -> Beginning of the file
$ -> End of file
The w or W command moves the cursor forward one word at a time
2w moves forward two words
Move backward by word, use the b or B command
5B moves back five words
Editing Text
cc — to change the entire line
cw – to the end of a word
c2b – back two words.
c$ – to the end of line.
c0- to the beginning of line.
r – replace a single character
dw – delete a word
.  ->  it is used to repeat the same operation, what you are doing
u -> undo
U -> undo all the changes in a single line
A ->Append text to end of current line.
I ->Insert text at beginning of line.
o ->Open blank line below cursor for text.
O-> Open blank line above cursor for text.
s-> Delete character at cursor and substitute text.
S-> Delete line and substitute text.
R-> Overstrike existing characters with new characters
J ->joins the line the cursor is on with the line below.
p or P -> Place text from buffer
Scrolling the Screen
ctrl + F Scroll forward one screen.
ctrl +B Scroll backward one screen.
ctrl + D Scroll forward half screen (down).
ctrl +U Scroll backward half screen (up).
Movement Within a Screen
H — Move to home – top line on screen.
M — Move to middle line on screen.
L — Move to last line on screen.
nH –Move to n lines below top line.
nL–Move to n lines above last line.
Movement by Text Blocks
e — Move to end of word.
E — Move to end of word (ignore punctuation).
( — Move to beginning of current sentence.
) — Move to beginning of next sentence.
{ — Move to beginning of current paragraph.
} — Move to beginning of next paragraph.
[[ –Move to beginning of current section.
]]–Move to beginning of next section.
Movement by Searches
/Pattern –> search for the pattern in unix
?Pattern –> to search the pattern in backward
n –> to search the next occurence of the pattern search
N –> Repeat search for the pattern in Opposite direction.
Recover VI file
Use the -r option with a file name to recover the edited buffer.
For example, to recover the edited buffer of the file practice after a system crash, enter:
$ vi -r practice
Display Line Number
set nu or set number –> to display line number
set nonumber –> to hide or clear line number

About mohan

This is Mohan Jayapalan author of TechPages Blog.I am a part time blogger and Currently working for private Software Concern.

© Copyright 2010-2016 · All Rights Reserved · Powered by WordPress ·