Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!killer!usource!frankb From: frankb@usource.UUCP (Frank Bicknell) Newsgroups: comp.unix.xenix Subject: Re: Request for VI macros Summary: vi macros Message-ID: <168@usource.UUCP> Date: 27 Feb 89 12:12:01 GMT References: <15549@oberon.USC.EDU> Organization: UniSource, Inc., Sarasota, FL Lines: 68 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. + some letter (like function keys) for neat stuff like: :map :e#^M :map :w^M:e#^M :map :m+^M :map :m-2^M BTW... the 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 , shifting and then back to 'i', use: :map! ^F ^[>>A :map! ^A ^[<