Troubleshooters.Com and T.C Linux Library Present

VI Quick Start

Copyright (C) 1999 by Steve Litt
[ Linux Library | Troubleshooters.Com | Email Steve Litt | Copyright Notice ]

Getting Help

Inside vi, :help (press the colon key, then type the word help, then press the enter key).

Starting VI

From the command prompt, type vi and press the enter key. Or, to edit a specific file, type vi, then a space, then the filename, then the enter key. Use the -R argument to edit a file in read-only mode.

Run the editor with no file
vi /etc/hosts
Edit /etc/hosts
vi -R /etc/hosts
Edit /etc/hosts in read-only mode -- view it

Quitting VI

From inside vi, press the colon key to get into command mode, then press the proper quit command:
Quit, no save, from an unmodified file. Gives an error message if the file has been modified since its last save.
Quit, no save, no confirmation, whether the file has been modified or not.
Write the file and quit.

Search and Replace

To substitute new for the first old on a line type
To substitute new for all 'old's on a line type 
To substitute phrases between two line #'s type
To substitute all occurrences in the file type
To ask for confirmation each time add 'c'


VI Tips:

If you want to eliminate every line EXCEPT those matching a search criteria:


Then, to sort the remainder:


Finally, to delete duplicates from your sorted file:


See also: [ Code Corner | Troubleshooters.Com | Email Steve Litt | Copyright Notice ]

Copyright (C)1997 by Steve Litt. -- Legal