Basic Linux Tutorial
Computer Tutorial

Starting and Stopping Vi



Starting and Stopping Vi

The editor is started when you use a Vi command and give a file name as its argument.
if you want to edit a file with the name generalnote, you will use :
$ vi generalnote
This command starts vi and allocates a memory buffer for file generalnote. If the file already exists, text in the file will be displayed on the screen. The bottom line, which is used as a status line, will display a file name, line number, and number of characters in the file. Remember that you can't add any text to the file until you go into insert mode because vi started in the command mode.

Vi Editor Screen

Vi Editor Screen

The tilde character (~) you see in the screen shot shows that the file has no text in these lines. To switch to insert mode, you press the i character just after starting vi.
When you have finished entering text into the file, you press the Esc & : key to return to command mode. To save the file, you can use the :w command. After you save the file, you can quit the editor with the :q command. You can also use :x or :wq to save and quit in one step.
Multiple files can be opened with vi by supplying multiple file names at the command line. If you want to open three files (file1, file2, file3) simultaneously, the command will be as follows :
$ vi file1 file2 file3