VI is the widely used text editor in UNIX operating systems. I have had the chance to use the VI editor in the Solaris and Linux operating systems. In this article we are going to learn how to use the VI editor.
To move your cursors in VI use the following commands (a long list!).
h
Move left
j
Move down
k
Move up
l
Move right
w
Move to next word
W
Move to next blank delimited word
b
Move to the beginning of the word
B
Move to the beginning of blank delimited word
^
Moves to the first non-blank character in the current line
+
Moves to the first character in the next line
-
Moves to the first non-blank character in the previous line
e
Move to the end of the word
E
Move to the end of blank delimited word
(
Move a sentence back
)
Move a sentence forward
{
Move a paragraph back
}
Move a paragraph forward
0 or |
Move to the beginning of the line
$
Move to the end of the line
:n
Move to nth line of the file
For jumping to the beginning of the document use [[, and use ]] to jump to the end of the document.
Deleting texts: To delete content use d and x. Use x for deleting character to the right of the cursor. Use d with the above operands (motion/movement operands) for deleting. To delete a word use dw (next word). Delete is basically cut, i.e. you can paste the deleted contents. The following are some other delete commands.
x
Delete character to the right of cursor
nx
Deletes n characters starting with the current one; omitting n deletes current character only
X
Deletes the character to the left of cursor
nX
Deletes the previous n characters; omitting n deletes the previous character only
D
Delete to the end of the line
D$
Deletes from the cursor to the end of the line
dd or :d
Deletes the current line
ndw
Deletes the next n words starting with the current word
ndb
Deletes the previous n words starting with the current word
ndd
Deletes n lines beginning with the current line
:n,md
Deletes lines n through m
Tips: You can edit multiple lines better if you know the line numbers. To show line numbers use the following command.