[svlug] Two stupid FAQ questions about VI...
Seth David Schoen
schoen at uclink4.berkeley.edu
Sun Nov 29 22:09:55 PST 1998
Sam Ockman writes:
> ....Alright I'm finally learning vi, and I have two questions that I
> can't find an answer to.
>
> 1) What's the equivalent to esq-q in emacs. I.e. I've just mananged to
> mangle a paragraph and need some way to reformat it so all the lines
> end at around 70 characters to the right margin.
!}fmt
or
!}par
For Par, see "http://http.cs.berkeley.edu/~amc/Par" -- I used it above
to reformat your quoted text (just for fun), and it worked very nicely.
Both fmt and par (which obsoletes fmt) have some useful options, including
line width. Actually learning to use par is something like actually
learning to use procmail, and I haven't done either. You might, instead,
want to use other people's recipes most of the time. :-)
vim has a built-in command of some sort for this function, but using an
external filter is the most portable (and par is probably more powerful
than vim's equivalent).
> 2) How do I count the number of words in the buffer?
If you've saved the buffer, you can see the number of words with
:!wc -w %
or read the number of words into the buffer with
:r!wc -w %
If you don't want to rely on having saved the buffer, you could
:1,$|wc -w
(which replaces the buffer with the number of words in it).
Then immediately
u
to get the buffer back!
As a more nondestructive solution (a less destructive solution?), you
could use a script like
#!/bin/sh
tee ~/count$$
wc -w <~/count$$
rm -f ~/count$$
If you call this "catcount", then you can
:1,$!catcount
to get the wordcount of the buffer appended to its end.
You can bind any of these to a particular keystroke in vi, if you like.
For instance,
:map # :r!wc -w %^M
would make "#" load the word count of the (already saved) buffer. You'll
need to type "^V^M" to produce the ^M there, however.
You could use the same technique to make a single-key version of any of
the ideas above:
:map @ !}par^M
You can also set such bindings in your .exrc.
--
Seth David Schoen L&S '01 (undeclared) / schoen at uclink4.berkeley.edu
He said, "This is what the king who will reign over you will do." And they
said, "Nay, but we will have a king over us, that we also may be like all the
nations." (1 Sam 8) http://ishmael.geecs.org/~sigma/ http://www.loyalty.org/
--
echo "unsubscribe svlug" | mail majordomo at svlug.org
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ to unsubscribe
see http://www.svlug.org/mdstuff/lists.shtml for posting guidelines.
More information about the svlug
mailing list