|
Softpanorama |
May the source be with you, but remember the KISS principle ;-)
|
| Old News ;-) | See Also | Recommended Links | Reference | History | Humor | Etc |
Simple description of the various 'vi' macro mechanisms
text abbreviation, which operates only in text-entry mode (the "abbr" ex-escape command); once set, an abbreviation works only in "vi" text-entry mode;keystroke remapping, which can operate either in text-entry or in command mode (the "map!" and "map" ex-escape commands); once set, a "map!"'ed sequence is triggered only in text-entry mode, and a "map"'ed sequence is triggered only in "vi" command mode;text-buffer execution, which operates only in command mode: once text has been placed in any of the named text buffers, that text can be executed as if it were a sequence of 'vi' commands.Text abbreviation
Using macros during text-entry is almost always motivated by the goal of just saving keystrokes. The text-abbreviation macro in 'vi' is set up by going to "ex-escape" mode by typing a colon, and has the form
abbr
where an example might be
abbr gatt General Agreement on Tariffs and Trade
[Note that the name of the text abbreviation cannot contain an embedded space. This is a limitation of all the 'vi' macro mechanisms except for text- buffer execution, which uses the names of the named text buffers to define which macro to execute; a buffer name is a single alphabetic letter.]
Once this is done, then while in text-entry mode, whenever you type a non-alphanumeric character followed by the string "gatt", 'vi' will examine the next character you type to see if it's non-alphanumeric, and if so, then "gatt" will be erased and "General Agreement on Tariffs and Trade" will be substituted for it. (Typing "gatt" at the very top of your text qualifies as a non-alphanumeric character followed by "gatt".)
If you don't want a particular instance of "gatt" to get converted, even though it's preceded and followed by a non-alphanumeric character, you have to escape the first character following "gatt" by typing
^V
(that is control-V), so if you want "gatt!" to appear, you type
gatt^V!
With text abbreviations, your text appears as you type it, and no transformation is performed on your specified abbreviation until you follow it with a non-alphabetic character (which includes an immediate exit from text-entry mode). This differentiates text abbreviation from text-mode keystroke-remapping using the "map!" command, which will be discussed soon. Text abbreviations can be canceled with the ex-escape "unabbr" command:
unabbr gatt
Most simple abbreviations can be unabbreviated via a simple ex-escape command, the kind you introduce by typing a colon from 'vi' command mode. But many cannot, especially mode-bouncing abbreviations, to be discussed later. For these, you must enter genuine "ex" mode by typing a capital Q ("Q") from 'vi' command mode. Then do your "unabbr gatt". To return to "vi" mode, enter "vi" or "visual" at the "ex" colon prompt.
You can get a list of your currently active abbreviations by entering simply "abbr" in ex-escape mode.
VI LOVERS HOME PAGE/Macros
Vi macros for writing HTML -- yes, there are masochists that use VI for writing HTML :-)
Copyright © 1996-2008 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
Standard disclaimer: The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.
Last modified: February 28, 2008