[comp.unix.xenix] Request for VI macros

rkumar@buddha.usc.edu (02/26/89)

Can someone educate me on how macros can be created in
vi, the editor? I am looking for simple things like
inserting templates (e.g, \begin{document} ,, \end{document})
when I use a single macro.

Thanks.

Ravi



:-) (-:
Yeh tere baap ka Oldsmobile nahin!
Tr : This is not your father's Oldsmobile
:-) (-:

frankb@usource.UUCP (Frank Bicknell) (02/27/89)

In article <15549@oberon.USC.EDU>, rkumar@buddha.usc.edu writes:
> Can someone educate me on how macros can be created in
> vi, the editor? I am looking for simple things like
> inserting templates (e.g, \begin{document} ,, \end{document})
> when I use a single macro.

Try this:

:map ^R i\begin{document} ,, \end{document}^[

(mighty strange macro you have there!)
But anyway, the control characters are preceded with a ^V to
prevent vi from interpreting them specially (like ^[ would
be the end of the line and end the macro).  The ^R is an
oddball in that it doesn't need the ^V...but that's another
issue.  

For inserting templates, you might use:

:map ^R :r file_name^M

Which would read in the file file_name.  If what you meant my
\(begin|end){document} was go to the (begin|end), then:

:map ^R 1G ,, G

...would do ya.  I'm not terribly sure what you want to do.
Basically, what you do is type in the commands you want to use,
but precede any control characters with ^V to hide them.  The
macro is assigned to the character (sequence) which appears
in the second field of the map statement (^R in my
examples).  Just pick some control character that doesn't do
something else and/or isn't duplicated some other way (Like
^R is duped by ^L).  I usually use ^R and ^T for on-the-fly
macros.  <esc> + some letter (like function keys) for neat
stuff like: 

:map <your f1 sequence here> :e#^M <edit the other file>
:map <your F1 sequence here> :w^M:e#^M
	<write this file then edit the other file>
:map <your f3 sequence here> :m+^M <move this line down one line>
:map <your F3 sequence here> :m-2^M <move this line up one line>

BTW... the <stuff> is comments for illustration: unfortunately,
I don't know of any way to comment vi macros... has anyone found
a solution to that one?

You can also put these statements in your .exrc file.  I have a
different .exrc for each terminal and link .exrc to the correct
one on login (that's how I handle the different function keys).

One last note (whew)... the macros I've been describing all take
effect from the command mode.  If you put a bang (!) after the
map command, the macro will be effective from insert mode.  Thus,
if you like to have hanging indents and don't want the bother of
hitting <esc>, shifting and then back to 'i', use:

:map! ^F ^[>>A
:map! ^A ^[<<A

These shift the whole line right and left, respectively then put
you back into insert mode at the end of the line.

---
:map! ^[ ^Mhi there!^M -- a .exrc addition for your favorite enemy.
-- 
Frank Bicknell; 1405 Main St, Ste 709; Sarasota, FL 34236-5701
killer!usource!frankb