Neatening Lines (Unix Power Tools, 3rd Edition)
17.28. Neatening Lines
Have you made edits that left some
of your lines too short or long? The fmt (Section 21.2) utility
can clean that up. Here's an example. Let's say you're editing a file
(email message, whatever) in vi and the lines
aren't even. They look like this:
This file is a mess
with some short lines
and some lines that are too long -- like this one, which goes on and on for quite
a while and etc.
Let's see what 'fmt' does with it.
You put your cursor on the first line and type (in command mode):
5!! Section 17.18
5!!fmt
which means "filter
(Section 17.18) 5 lines through
fmt." Then the lines will look
like this:
This file is a mess with some short lines and some lines that are too
long -- like this one, which goes on and on for quite a while and etc.
Let's see what 'fmt' does with it.
This is handiest for formatting paragraphs. Put your cursor on the
first line of the paragraph and type (in command mode):
!}fmt
If you don't have any text in your file that needs to be kept as is,
you can neaten the whole file at once by typing:
% Section 20.3
:%!fmt
There are a few different versions of fmt, some
fancier than others. Most of the articles in Chapter 21 about editing-related tools can be handy too.
For example, recomment reformats program comment
blocks. cut (Section 21.14) can remove columns, fields, or shorten lines;
tr (Section 21.11)
can do other transformations. To neaten columns, try filtering
through with the setup in Section 21.17. In
general, if the utility will read its standard input and write
converted text to its standard output, you can use the utility as a
vi filter.
-- JP
17.27. Out of Temporary Space? Use Another Directory17.29. Finding Your Place with Undo
Copyright © 2003 O'Reilly & Associates. All rights reserved.
Wyszukiwarka
Podobne podstrony:
ch17 (2)ch17 (24)ch17#ch17&ch17ch17CH17 (15)ch17ch17ch17 (9)ch17ch17 (6)ch17ch17CH17ch17więcej podobnych podstron