Nice vi Trick
Bill Campbell
linux-sxs
Sun Jan 8 17:32:48 PST 2006
On Sat, Jan 07, 2006, Kurt Wall wrote:
>On Sat, Jan 07, 2006 at 06:16:34PM -0800, Bill Campbell took 40 lines to write:
>> On Sat, Jan 07, 2006, Kurt Wall wrote:
>> >If you're using vi/vim/elvis and want to center a line of text,
>> >enter this command:
>> > :<range>center
>
>[...]
>
>> We have had a recurring series of ``Stupid Vi Tricks'' at the
>> Seattle Unix Group meetings. One example may be found here:
>>
>> http://www.seaslug.org/Meetings/1995/Aug_vi_tricks.html
>
>Nice. I like vi enough that I usually install nvi right after install
>a new or updated distribution. After looking at that page, I remember
>that I wanted to remember to play with named buffers. Are they related
>to vi macros (which I believe are just keyboard macros)?
I'm not familiar with nvi. I look at alternates to vi occassionaly, but
haven't found anything else that is as efficient and useful for my work
which is mostly editing program files and scripts (I couldn't live without
the ``%'' key to match braces and parenthesis). I started using vi on the
Radio Shack Model 16 Xenix almost 24 years ago.
There are 26 named buffers, ``a'' through ``z'' as there are 26 marks that
may be used to mark locations in the text. The buffers may be used to
store text for later retrieval. Ihey may be used to store commands to be
used in later by pressing ``@<bufferletter>''. This is particularly useful
when one needs to create complex regular expressions in substitutions.
Create the substitution on a line. Delete that line into a named buffer,
then execute that command.
Create a line, perhaps this to substitute a pattern throughout
the document:
:%s/pattern1/pattern2/g
Place the cursor on that line, and enter this to delete the line
into buffer ``s'':
'sdd
Then to execute that, type ``@s'' from command mode.
If the command doesn't work properly, yank it back into the page using
``"sp'' to ``put'' it below the current line, edit it and repeat the
delete, execute sequence. Named buffers are referenced using the syntax
"<bufferletter><action> (double quote, buffer letter, and an action like
``p'' to put below or ``P'' to put above the current line).
Bill
--
INTERNET: bill at Celestial.COM Bill Campbell; Celestial Systems, Inc.
URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676
``there is nothing more difficult to take in hand, more perilous to
conduct, or more uncertain in its success, than to take the lead in
the introduction of a new order of things. Because the innovator has
for enemies all those who have done well under the old conditions,
and lukewarm defenders in those who may do well under the new.''
-- Machiavelli
More information about the Linux-users
mailing list