How do I reformat paragraphs in vi?
Jerry Peek
jdpeek at RODAN.ACS.SYR.EDU
Sun Aug 27 06:49:47 AEST 1989
In article <263 at chip.UUCP> ss at chip.UUCP (Steve Schossow) writes:
> I'm writing this with vi. I know how to set my wrapmargin to get the
> paragraphs to break properly when I'm entering text. But what if I
> re-arrange the text after entering it. How do I get vi to reformat the
> result? Does someone have a macro that will do what I need?
"vi" lets you feed a chunk of text from your buffer to an external
command, then read the result back to replace the original text. Do
this with vi's ! (exclamation point) command. The format is:
!<where-to><filter_command>
where <where-to> is a "vi" where-to command like "}", "23G", "L", etc.
and <filter_command> is a utility like "fmt" (if you have it).
For example, to clean up the current paragraph, put your cursor on the
first line and type:
!}fmt (then press RETURN)
to do this paragraph and two more:
!3}fmt
To clean up the rest of the file, use:
!Gfmt
A count of lines works, too. For instance, to format this line and three more:
4!!fmt
If your system doesn't have "fmt", there are public-domain ones around.
Once I wrote a shell script that used "nroff," plus a few nroff commands,
to do centering of lines. Any program that reads stdin and writes stdout
will work. My favorite is a shell script like "fmt" called "recomment".
It reformats comments in program source by figuring out what the comment
character(s) are, neatening the lines and putting back the comment characters.
--Jerry Peek; Syracuse University Academic Computing Services; Syracuse, NY
jdpeek at rodan.acs.syr.edu///JDPEEK at SUVM.BITNET///GEnie: J.PEEK1
+1 315 443-3995
More information about the Comp.unix.questions
mailing list