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!).
Move to next word
Move to next blank delimited word
Move to the beginning of the word
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
Move to the end of the word
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
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.
Delete character to the right of cursor
Deletes n characters starting with the current one; omitting n deletes current character only
Deletes the character to the left of cursor
Deletes the previous n characters; omitting n deletes the previous character only
Delete to the end of the line
Deletes from the cursor to the end of the line
dd or :d
Deletes the current line
Deletes the next n words starting with the current word
Deletes the previous n words starting with the current word
Deletes n lines beginning with the current line
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.