The VI editor is a screen-based editor. It is very powerful and has been around for more than a decade. Programmers are especially fond of the VI editor due to its powerful features to aid programmers. VI is often overwhelming for beginners. It takes some time to get used to VI but it is often well worth the effort. The key to mastering VI is to learn sequentially, getting used to the commands you learn at each step.
Starting the VI Editor
VI editor lets you create new files or edit existing files. The command to start is:
vi filename
Then you hit return. If the file exists, it will open for editing. Otherwise it vi will create a new file with that name.
At the bottom of your screen, you will see the filename and the filesize. Something like:
"filename" 234 lines, 3685 characters
Quitting VI editor
VI editor runs in two modes: edit mode and command mode. To quit VI, you need to be in command mode. If you are not in command mode, you need to hit the Esc key on your keyboard to exit the edit mode to the command mode.
To quit without saving changes, type:
:q!
To quit saving changes, type either:
:wq
or
ZZ
Then hit return.
Useful Commands
Following are some useful commands:
$ vi - this open a new file
$ vi somefile.txt - this opens somefile.txt. If it doesn't exist, it creates it.
$ vi /home/somesite/somefile.txt - unix addresses can be used
:ZZ - save and exit
:wq - save and exit
:w - save
:w >> filename - append to file
:q - quit
:q! - quit with saving
:e! - wipe all changes and return to original file
Modes
VI editor has two modes:
- command mode: allows for text manipulation
- insert mode: allows for text insertion into the file
VI starts out in command mode. There are several commands that put the VI editor into insert mode: i, s, a, c, r, etc. Each of these commands is slightly different and they are discussed later. To get back to insert mode, you need to hit Esc.
Comments
Where is EMACS? EMACS kicks
Where is EMACS? EMACS kicks VI's ass. So include a column about EMACS!!