Vi Text Editor
Linux text Editors
Vi Editor
To call the VI editor and begin an editing session, type at the Linux prompt ($):
$ vi filename [RETURN]
where filename is the name of the file that you want to edit. VI automatically sets aside a temporary buffer as a working space for use during this editing session.
If the file you specify when calling VI does not already exist in your current working directory, a new file will be created with the name that you have specified. For example, if you wanted to create a new file called jobjar, you would type:
$vi jobjar [RETURN]
The screen will flicker and clear and you will see:

When the VI editor creates a new file as in the previous example, the cursor will be placed on the screen in the home position (upper left-hand corner). The cursor on most terminals is a rectangle that completely covers the character space it is situated upon and reflects your current position within the buffer. Below the cursor along the left side of the screen, is a tilde ( ~ ) character positioned in the first character space on each line. The tilde is used to indicate a void area in the file where there are no characters, not even blank spaces. At the bottom of the screen, the editor displays a file information line which presents the name of the file being edited, in this case jobjar, followed by "[New file]" to indicate that this is a new file and it has never been opened before.
The VI editor allows a user to modify and add material to an already existing file. This is done by using the name of a current file when calling VI. VI will then fetch a copy of the contents of the specified file from disk storage, leaving the original undisturbed, and place the copy into the buffer. It is here, in the buffer, where VI permits you to do your editing. The idea of editing in the buffer is very beneficial, because if you really botch up your editing job (such as deleting a major section) the original file on the disk remains unaffected.
Upon opening a file, VI will display the first screenful of text starting at the top of the file, place the cursor in the home position, and print the file information line which displays the name of the file along with the number of lines and characters it contains on the last line of the screen. For example, to edit the file sample which has 40 lines and 750 characters, call the VI editor with this command:
$vi sample [RETURN]
The screen will flicker and clear. Then you will see:

As shown in this example the cursor sits in the home position, it completely overlays the first character of the file. When the cursor is moved, this character will be exposed, unchanged. In general, most terminal screens will display only 20 to 24 lines of text. If a file has more text than will fit on one screen, the unviewed material remains in the buffer until needed.
As mentioned before, when the VI editor is invoked a temporary working area is created called a buffer. This buffer or work space is only available for your use while you are using the editor. It is into this buffer that VI either places a duplicate copy of the file as it exists on the disk or creates a new file. When you exit the editor, this work area is discarded. Disk storage, on the other hand, can be thought of as a permanent storehouse for files until discarded by using the UNIX remove command.
Few things are more upsetting than to spend many hours keying information into a file, simply to have a careless keystroke close the buffer and destroy your work. Material you have keyed into the buffer file is only retained for future access when the file is "saved" on the disk. Material not "saved" on the disk is discarded when exiting VI and the buffer is closed.