home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 30.36 The ex Open Mode Can Be Handy Chapter 30
vi Tips and Tricks
Next: 30.38 Finding Your Place with Undo
 

30.37 Neatening Lines

Have you made edits that left some of your lines too short or long? The fmt (35.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!!
 
5!!

fmt

which means " filter (30.22 ) 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:

%
 
:

%

!fmt

There are a few different versions of fmt , some fancier than others. Most of the articles in the chapter about editing-related tools can be handy too. For example, recomment (35.4 ) reformats program comment blocks. cut (35.14 ) can remove columns, fields, or shorten lines; tr (35.11 ) can do other transformations. To neaten columns, try filtering through with the setup in article 35.22 . 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


Previous: 30.36 The ex Open Mode Can Be Handy UNIX Power Tools Next: 30.38 Finding Your Place with Undo
30.36 The ex Open Mode Can Be Handy Book Index 30.38 Finding Your Place with Undo

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System