Examples:
vi |
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 |
:q |
Quit, no save, from an unmodified file. Gives an error message if the file has been modified since its last save. |
:q! |
Quit, no save, no confirmation, whether the file has been modified or not. |
:wq |
Write the file and quit. |
To substitute new for the first old on a line type |
s/old/new |
To substitute new for all 'old's on a line type |
s/old/new/g |
To substitute phrases between two line #'s type |
#,#s/old/new/g |
To substitute all occurrences in the file type |
%s/old/new/g |
To ask for confirmation each time add 'c' |
%s/old/new/gc |
:g!/searchstring/d
Then, to sort the remainder:
:%!sort
Finally, to delete duplicates from your sorted file:
:%!uniq
See also: [ Code Corner | Troubleshooters.Com | Email Steve Litt | Copyright Notice ]