Last month’s column introduced you to the venerable Unix editor vi. This month’s column describes several of vi’s more advanced capabilities, which set it apart from other editors. By the end of this column you’ll know how to perform editing feats that are quite cumbersome without the help of vi.
Last month’s column introduced you to the venerable Unix editor vi. This month’s column describes several of vi’s more advanced capabilities, which set it apart from other editors. By the end of this column you’ll know how to perform editing feats that are quite cumbersome without the help of vi.
Editors Within Editors
As explained in our previous Newbies column, vi is really two types of editors in one. The older ex editor has been incorporated into vi, and any commands beginning with a colon (:) are passed to ex for execution.
What wasn’t fully revealed last month, however, is that the ex editor, though older than the rest of vi, is capable of performing some pretty sophisticated actions. Let’s begin by considering Table One, which summarizes some important ex commands.
Table One: Selected ex Commands
Command
Description
d
Delete specified lines
g/pattern/command
Execute specified command on lines containing pattern
g!/pattern/
Execute specified command on lines not containing pattern
m location
Move lines to specified location
r filename
Insert text from specified file
s/pattern/replacement/
Substitute instances of pattern with replacement
t location
Copy lines to specified location
! command
Execute a shell command
In addition to the commands shown in Table One,ex handles several other important commands that were examined in last month’s column, including the commands to write the current file and exit vi.
Deleting Lines
The previous Newbies column showed how…
Please log in to view this content.
Not Yet a Member?
Register with LinuxMagazine.com and get free access to the entire archive, including: