VI Editing Commands
Here you can find the basic of vi editing, you will find quite helpful;
Editing commands
Moving around the file:
h β cursor left
i β cursor right
k β cursor up
j β cursor down
^ & B β Beginning of line
$ β end of line
) β Next sentence
( β Previous sentence
} β Next Paragraph
{ β Previous Paragraph
:$ β end of file
w β one character forward
W β one word forward
:20 β go to Line no 20 or whatever number you give
Displaying file info:
^g β give name of the file, current line and total lines of a file at the bottom.
Inserting and appending text :
i β inserts text to the left of cursor
I β inserts in the beginning of line
a β appends text to right of cursor
A β appends to the end of line
Adding new line:
o β add a new line below the current line
O β adds a new line above the current line.
Deleting the text:
x β deletes text above the cursor
X β deletes text character on the right of cursor
20dd β deletes 20
dd β deletes current line
D β delete till end of current line.
d# β delete to where the # (j,k,l,h) specifies.
d/ β delete till pattern is found (forward).
d? β delete till pattern is found (backward).
dβ β delete till mark βcharβ.
Replacing a character & word:
r β replace the character above the cursor.
R β replces characters until Esc is pressed.
cw β replaces the word from cursor to the end indicated by $ sign.
C β replaces till end of line.
Substitute:
s β subistutes current charcater.
S β substitutes entire line.
Repeating last command:
. β repeats the last text.
Undo the last change:
u β undo last change.
U β undo changes to the current line.
Copy and pasting lines:
yy β copies the current line into buffer.
5yy β copies 5 lines from the current line.
p β pastes the current buffer.
Recovering an unsaved vi file:
vi -r β restores a unsaved / crashed file from buffer.
Searching:
:/name β & return searches for the word name in the file
n β continues search forward.
N β searches backwards.
Substitution:
:s///g
Saving:
:w β saves the text does not quit.
:wq β saves & quit the editor.
ZZ β save & quit the editor.
:q! β Quit without saving.
Miscellaneous:
m β mark this location and name it char.
β β (quote character) return to βlineβ named char.
` β (back-quote character) return to βplaceβ named char.
ββ or β β (quote quote) return from last movement.
Sphere: Related Content

























