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.
Use :w for saving the content and :q for quitting. Here are some examples.
:w
Saves current file but doesn't exit
:w file
Saves current content as file but doesn't exit
:n,mw file
Saves lines n through m to file
:n,mw >>file
Saves lines n through m to the end of file
:q
Quits VI and may prompt if you need to save
:q!
Quits VI without saving
ZZ or :wq
Saves and exits VI
VI has two modes; one is the command mode and the other is the edit mode. To change to the edit mode you have to use i (insert) or a (append). Use the ESC character to change back to command mode.
Inserting texts: Use i, I, a, A, o or O for insertion as described in the following table.