🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.editors
Article #3083

Re: Reformatting in vi

#3083
From: James T. Perkins;1149;92-725;LP=...
Date: Thu, 04 Feb 1988 20:13
110 lines
5434 bytes
In article <1806@ttidca.TTI.COM> kevin@ttidcb.tti.com (Kevin Carothers) writes:

>>While it's true that vi gets a lot of bad (read "undeserved") press, I would
>>*not* consider this a shining example of its power.  In GNU Emacs, one moves
>>the point into the paragraph to be filled (assuming fill-mode is on), and
>>types ESC q to reformat the paragraph.  *No* blank lines are inserted.

>One thing that makes vi "powerful" on UNIX is that  it's  as
>closely  coupled  with  UNIX as "csh".  That is, whether one
>decides to format with "nroff", "fmt", or his/her  own  text
>pre-processor,  it's  totally  possible,  and just a command
>line away....

>Sure, a lot of text editors have a feature or two  for  mas-
>saging  a  paragraph or a margin. But  it's about useless if
>it's not *exactly* what you need/want. Why have a  bunch  of
>paragraph  formatters  around  when  mastery of one would be
>much more desireable?  The beauty of  vi  that I  stress  to
>people  who  don't  learn  it  (or don't think they have the
>patience to) is that you can  take advantage of  just  about
>everything UNIX has to offer *INSIDE* the editor.

I think what Kevin is trying to say is that vi is tied  into  the
UNIX shell closely enough and is powerful enough that you can use
any formatting program you want, instead of being limited to  one
packaged  with  and tied into the editor (like Wordstar paragraph
reformatting, to take an example--yech).

Its adamantly true that with most emacsi you could edit the ESC-q
paragraph  formatting function, or write a different one and bind
ESC-q to it instead of the default.

But you can do the same just as easily with vi.  What Kevin seems
to  be trying to say is that vi is every bit as powerful as emacs
in this way, in that you can map a key or sequence of  keys  (say
*p  to format a paragraph) to any imaginable formatting UNIX pro-
cess.

I myself have three vi paragraph formatters I use frequently, one
called  fmt  (a rewritten version of the Berekeley fmt program --
very like the rfm program posted here last week) that's  simplem-
inded  but  speedy and effective; cfmt which formats C-style com-
ments (I wrote it myself and it's a hack, but it's adequate); and
nfmt:

	:
	nroff | awk '
		{text[NR] = $0}
	NF>0	{last=NR}
	END	{for (i=1; i<=last; i++) print text[i]}' -

which runs nroff on the paragraph and then  strips  off  all  the
trailing blank lines (should be at least as powerful as the stan-
dard EMACS ESC-q).

Also, in my personal vi environment I can switch  between  nroff,
text, and c editing modes, with certain keystrokes and formatting
options set up for the appropriate editing mode.  Hence  in  text
mode,  the autowrap is set to maintain a two-character right mar-
gin, tabs are 8 characters wide and Q is mapped to !}fmt<CR>.  In
C mode, the autowrap is turned off, tabs are 4 characters wide, Q
is mapped to !}cfmt<CR>, and I have special maps to automatically
insert header comments; I could also enable commands to automati-
cally expand common C constructs; for example  typing  if'  while
inserting text, the editor would instantly expanded it to:

	if (_)
	{
	}

(the cursor is in insert mode at the "_").  I can switch  between
the modes simply by typing ",,".

And as far as I know most vi's will handle this degree of person-
alization.  BTW, this document was formatted with nfmt.

---

I'm not trying to tell emacs users to switch  to  vi.   I'm  just
telling vi users to explore vi and realize the beauty therein and
it's advantages and disadvantages.  Most vi users, even those us-
ing  vi  for 10 years, only use 50% of the capability of vi.  The
other 50% of vi allows at least a 2x productivity improvement.

Personally I have gotten used to thinking orthogonally when edit-
ing (example: hm.  Change next 3 paragraphs to "mary had a little
lamb", to beginning of line, yank first 3 words, 6 lines up,  put
before  the  cursor,  Indent two paragraphs by a tabstop, etc. --
translates to:

	c3}mary had a little lamb<ESC>
	^
	y3w
	6k
	P
	>2}

The most powerful feature of vi to me is the motion arguments  to
commands  (ex:  change *3* *paragraphs*, yank *3* *words*).  This
is like a simple english sentence with a  verb,  optional  count,
and  an  object.   Its  very mnemonic and for me it would be very
painful to have to remember a different pair  of  keystrokes  for
every little variation of yank, change, delete, etc.

 _	___
| |    / _ \   James T. Perkins, jamesp@dadla.la.tek.com, (503)629-1149
| |__ | |_| |  Tektronix Logic Analyzers, DAS System Software, Disk Services
|____||_| |_|  MS 92-725, PO Box 4600, Beaverton OR 97075

Killed processes never die... They just go to the big Bit Bicket in the sky.
Technical Details
Message-ID: <3099@zeus.TEK.COM>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!nrl-cmf!cmcl2!brl-adm!husc6!mit-eddie!uw-beaver!tektronix!zeus!dadla!jamesp
References: <1988Jan19.102343.3255@nonvon.uucp> <1723@ttidca.TTI.COM> <1726@ttidca.TTI.COM> <3774@xanth.cs.odu.edu> <1806@ttidca.TTI.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!nrl-cmf!cmcl2!brl-adm!husc6!mit-eddie!uw-beaver!tektronix!zeus!dadla!jamesp
From: jamesp@dadla.TEK.COM (James T. Perkins;1149;92-725;LP=A;60eC)
Newsgroups: comp.editors
Subject: Re: Reformatting in vi
Message-ID: <3099@zeus.TEK.COM>
Date: 4 Feb 88 20:13:05 GMT
References: <1988Jan19.102343.3255@nonvon.uucp> <1723@ttidca.TTI.COM> <1726@ttidca.TTI.COM> <3774@xanth.cs.odu.edu> <1806@ttidca.TTI.COM>
Sender: news@zeus.TEK.COM
Reply-To: jamesp@dadla.la.tek.com (James T. Perkins)
Distribution: na
Organization: Tektronix, Inc., Beaverton, OR.
Lines: 109