Sunday, April 27, 2008

VI/VIM Editior

All Linux configuration files are written in plain English, easy to read and to adapt. You use a text-editor to write or make changes to such files. The two most popular, powerful, and unfortunately "difficult" text editors, both of which are found in every Linux distro, are Vi and Emacs.
Most GUI-based editors, such as Kedit, are easier to manage. But don't make the mistake of thinking that a GUI-based editor is all you need. There are situations that crop up with Linux that require a text-mode editor -- in other words, when you don't have the luxury of accessing a GUI desktop at all. Vi and Emacs are the only tools that come with every Linux distro that work in text mode, so learning one or the other is mandatory.
The advantage of learning vi and learning it well is that one will find vi on all Unix based systems and it does not consume an inordinate amount of system resources. Vi works great over slow network ppp modem connections and on systems of limited resources. One can completely utilize vi without departing a single finger from the keyboard. (No hand to mouse and return to keyboard latency)
The vim editor is an enhanced version of vi. The improvements are clearly noticed in the handling of tags.
The vi editor has three modes, command mode, insert mode and command line mode.
Command mode: letters or sequence of letters interactively command vi. Commands are case sensitive. The ESC key can end a command.
Insert mode: Text is inserted. The ESC key ends insert mode and returns you to command mode. One can enter insert mode with the "i" (insert), "a" (insert after), "A" (insert at end of line), "o" (open new line after current line) or "O" (Open line above current line) commands.
Command line mode: One enters this mode by typing ":" which puts the command line entry at the foot of the screen.
Terminate session:
Use command: ZZ
Save changes and quit.
Use command line: ":wq"
Save (write) changes and quit.
Use command line: ":w"
Save (write) changes without quitting.
Use command line: ":q!"
Ignore changes and quit. No changes from last write will be saved.
Use command line: ":qa"
Quit all files opened.
Example:
Consider you want to create a normal file, named as “examplefile”.
]# vi examplefile
To write in this file, Press “Insert” key or “i”
To select the complete line and copy Press “yy” and for paste Press “p”, Make sure you are not in interesting mode.
To save file after writing, Press “Esc” and then “:s” for save and “:q” for quit
To save and quit with single command Press “Shift+zz”
To quit without saving just type “:q!”

No comments: