Vi For Smarties
Lesson Three
Colon Commands (Ed/Ex Commands)
- Use : (colon) in command mode before entering
complex commands.
Example: :%s/foo/bar/g replaces all occurrences of
foo with bar in the entire file.
Example: :set nu displays line numbers.
Example: :set nonu cancels line number display.
Example: :1,8d deletes lines 1 through 8 inclusive.
Useful Colon Commands
- Use :set wm=8 to make text wrap around to a new line
if it goes beyond column 72 of the current line. (80-8=72) The 8 can be
some other value if you wish, of course.
- Use :set ts=4 to set the number of spaces used to
display the tab character to 4. The 4 can be some other value if you
wish.
- Use :set ic to make string searches with
/ ignore cases.
Example: After :set ic using /foobar
will find foobar as well as FooBaR.
Marking Text Regions
- Use ma to mark the current line as a.
The a can be any letter from a to
z. The line can then be referenced by using
'a (single quote followed by a or appropriate
letter).
Example: 'a goes to the line marked as
a.
- Marked lines can be used in colon commands.
Example: :'a,'b d deletes all lines from the line marked
as a to the line marked as b,
inclusive.
Other Useful Colon Commands
- Use :w newfile.txt to save to a new file called
newfile.txt.
- Use :set all to find out the value of all options
set.
- Use :8,16 co 32 to copy lines 8
through 16 to the spot after line 32.
- Use :8,16 m 32 to move lines 8
through 16 to the spot after line 32.
- If you have multiple files open for editing, use :n
to go the next file in the sequence. If you are at the end of the
sequence, use :rew to rewind to the
beginning and start again with the first file in the sequence.
- Use :args to list all the open files in order.
Until you have mastered everything on this page, you are
not ready for Lesson Four.
Copyright © 2001
jerry_y_wang@yahoo.com.
All rights reserved.