Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!gem.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!RODAN.ACS.SYR.EDU!jdpeek From: jdpeek@RODAN.ACS.SYR.EDU ("Jerry Peek") Newsgroups: comp.unix.questions Subject: Re: How do I reformat paragraphs in vi? Keywords: vi paragraph reformat Message-ID: <8908261949.AA22491@rodan.acs.syr.edu> Date: 26 Aug 89 20:49:47 GMT References: <263@chip.UUCP> Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: jdpeek@rodan.acs.syr.edu.uucp (Jerry Peek) Distribution: na Organization: Syracuse University, Syracuse, NY Lines: 33 In article <263@chip.UUCP> ss@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 is a "vi" where-to command like "}", "23G", "L", etc. and 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@rodan.acs.syr.edu///JDPEEK@SUVM.BITNET///GEnie: J.PEEK1 +1 315 443-3995