VI Editor is a powerful and mostly used text editor in Unix
operating system. It is known for its efficiency, speed etc.
There are few modes in edior. The most common are Insert mode
and Command-Line mode. In insert mode, you can insert and edit
text which is in file. While the Command-Line mode allows you
to save, exit, search and replace tasks.
Let's have a look to eplanation of vi and some shortcuts as
well.
* vi filename (Open a file)
* 'i' (You can insert in a file to edit before cursor)
* 'I' (Insert at the begining of a line)
* 'a' (Enter insert mode after cursor)
* 'A' (Enter insert mode end of the line)
* 'w' (To save your file and continue your edit)
* 'wq' (Save and exit)
* 'esc' (Switch to command mode from insert or etc.)
* 'h, j, k, l' (Navigate left, down, up, and right respectively)
* '0' (Move to the begining of a line)
* '$' (Move to the end of the line)
* 'G' (Go to the end of the file)
* 'gg' (Go to the beginning of the file)
* '(n)G' (Go to line number n)
* 'G' (Go to last line in a file)
* 'GA' (Go to last line and enter in insert mode)
* 'x' (Delete the character under the cursor)
* 'dd' (Delete the current line you are at)
* 'D' (Delete from the cursor position to the end of the line)
* 'yy' (Copy current line)
* 'p' (past copied line)
* 'yw' (yank a word)
* 'Xdd' (Delete X number of line)
* 'Xyy' (Yank X number of line)
* 'b' (Go to begining to the word)
* 'e' (Go to end of the word)
* ':num' (Display the current line's line number)
* '/pattern' (Search forward for a pattern)
* '?pattern' (Search backward for a pattern)
* 'n' (Move to the next occurrence of the search pattern)
* 'N' (Move to the previous occurrence)
* ':s/old/new' (Replace the first occurrence of "old" with "new" on the current line)
* ':%s/old/new/g' (Replace all occurrences of "old" with "new" in the entire file)
* ':n,ms/old/new/g' (Replace in lines n through m)
There are few things more like you can set your preference,
keybindings and other settings in your home directory by
creating a file ".vimrc". There is a enhanced version available
for vi which is called vim. You can do some fun with trying
above things with vim as well.