x
Loading
 Loading
Hello, Guest | Login | Register

The Truth About Text — Part III

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

CommandDescription
dDelete specified lines
g/pattern/commandExecute specified command on lines containing pattern
g!/pattern/Execute specified command on lines not containing pattern
m locationMove lines to specified location
r filenameInsert text from specified file
s/pattern/replacement/Substitute instances of pattern with replacement
t locationCopy lines to specified location
! commandExecute 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:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!
Username

Password

Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. Helpful Tools for Software Developers
  2. The Github Hall of Fame
  3. Book'em, Github.
  4. This Week on Github: Stupid Ruby Tricks
  5. A Veritable Scatter Shot!
Follow Linux Magazine
Rackspace