home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / mac / vim55rt.sit / runtime / doc / map.txt < prev    next >
Encoding:
Text File  |  1999-09-25  |  30.9 KB  |  776 lines  |  [TEXT/MPS ]

  1. *map.txt*       For Vim version 5.5.  Last change: 1999 Sep 17
  2.  
  3.  
  4.           VIM REFERENCE MANUAL    by Bram Moolenaar
  5.  
  6.  
  7. Key mapping and abbreviations.
  8.  
  9. 1. Key mapping            |key-mapping|
  10. 2. Abbreviations        |abbreviations|
  11. 3. User-defined commands    |user-commands|
  12.  
  13. ==============================================================================
  14. 1. Key mapping                    *key-mapping* *mapping*
  15.  
  16. There are commands to enter new mappings, remove mappings and list mappings.
  17. See |map-overview| for the various forms of "map" and their relationships with
  18. modes.
  19.  
  20. :map     {lhs} {rhs}                    *:map*
  21. :nm[ap]  {lhs} {rhs}                    *:nm* *:nmap*
  22. :vm[ap]  {lhs} {rhs}                    *:vm* *:vmap*
  23. :om[ap]  {lhs} {rhs}                    *:om* *:omap*
  24. :map!    {lhs} {rhs}                    *:map!*
  25. :im[ap]  {lhs} {rhs}                    *:im* *:imap*
  26. :cm[ap]  {lhs} {rhs}                    *:cm* *:cmap*
  27.             Map the key sequence {lhs} to {rhs} for the modes
  28.             where the map command applies.  The result, including
  29.             {rhs}, is then further scanned for mappings.  This
  30.             allows for nested and recursive use of mappings.
  31.  
  32.  
  33. :no[remap]   {lhs} {rhs}                *:no*  *:noremap*
  34. :nn[oremap]  {lhs} {rhs}                *:nn*  *:nnoremap*
  35. :vn[oremap]  {lhs} {rhs}                *:vn*  *:vnoremap*
  36. :ono[remap]  {lhs} {rhs}                *:ono* *:onoremap*
  37. :no[remap]!  {lhs} {rhs}                *:no!* *:noremap!*
  38. :ino[remap]  {lhs} {rhs}                *:ino* *:inoremap*
  39. :cno[remap]  {lhs} {rhs}                *:cno* *:cnoremap*
  40.             Map the key sequence {lhs} to {rhs} for the modes
  41.             where the map command applies.  Disallow mapping of
  42.             {rhs}, to avoid nested and recursive mappings.  Often
  43.             used to redefine a command.  {not in Vi}
  44.  
  45.  
  46. :unm[ap]   {lhs}                    *:unm*  *:unmap*
  47. :nun[map]  {lhs}                    *:nun*  *:nunmap*
  48. :vu[nmap]  {lhs}                    *:vu*   *:vunmap*
  49. :ou[nmap]  {lhs}                    *:ou*   *:ounmap*
  50. :unm[ap]!  {lhs}                    *:unm!* *:unmap!*
  51. :iu[nmap]  {lhs}                    *:iu*   *:iunmap*
  52. :cu[nmap]  {lhs}                    *:cu*   *:cunmap*
  53.             Remove the mapping of {lhs} for the modes where the
  54.             map command applies.  The mapping may remain defined
  55.             for other modes where it applies.
  56.             Note: Trailing spaces are included in the {lhs}.  This
  57.             unmap does NOT work:
  58. >                :map @@ foo
  59. >                :unmap @@ | print
  60.  
  61. :mapc[lear]                        *:mapc*   *:mapclear*
  62. :nmapc[lear]                        *:nmapc*  *:nmapclear*
  63. :vmapc[lear]                        *:vmapc*  *:vmapclear*
  64. :omapc[lear]                        *:omapc*  *:omapclear*
  65. :mapc[lear]!                        *:mapc!*  *:mapclear!*
  66. :imapc[lear]                        *:imapc*  *:imapclear*
  67. :cmapc[lear]                        *:cmapc*  *:cmapclear*
  68.             Remove ALL mappings for the modes where the map
  69.             command applies.  {not in Vi}
  70.             Warning: This also removes the default mappings.
  71.  
  72. :map
  73. :nm[ap]
  74. :vm[ap]
  75. :om[ap]
  76. :map!
  77. :im[ap]
  78. :cm[ap]
  79.             List all key mappings for the modes where the map
  80.             command applies.  Note that ":map" and ":map!" are
  81.             used most often, because they include the other modes.
  82.  
  83. :map     {lhs}                        *:map_l*
  84. :nm[ap]  {lhs}                        *:nmap_l*
  85. :vm[ap]  {lhs}                        *:vmap_l*
  86. :om[ap]  {lhs}                        *:omap_l*
  87. :map!    {lhs}                        *:map_l!*
  88. :im[ap]  {lhs}                        *:imap_l*
  89. :cm[ap]  {lhs}                        *:cmap_l*
  90.             List the key mappings for the key sequences starting
  91.             with {lhs} in the modes where the map command applies.
  92.             {not in Vi}
  93.  
  94. These commands are used to map a key or key sequence to a string of
  95. characters.  You can use this to put command sequences under function keys,
  96. translate one key into another, etc.  See |:mkexrc| for how to save and
  97. restore the current mappings.
  98.  
  99. There are five sets of mappings
  100. - For Normal mode: When typing commands.
  101. - For Visual mode: When typing commands while the Visual area is highlighted.
  102. - For Operator-pending mode: When an operator is pending (after "d", "y", "c",
  103.   etc.).
  104. - For Insert mode. These are also used in Replace mode.
  105. - For Command-line mode: When entering a ":" or "/" command.
  106.  
  107. There are no separate mappings for Select mode.  The same as for Visual mode
  108. are used |Select-mode-mapping|.
  109.  
  110.                         *map-overview* *map-modes*
  111. Overview of which map command works in which mode:
  112.  
  113.     commands:                      modes:                  ~
  114.                       Normal     Visual  Operator-pending ~
  115. :map   :noremap   :unmap   :mapclear         X        X       X
  116. :nmap  :nnoremap  :nunmap  :nmapclear         X        .       .
  117. :vmap  :vnoremap  :vunmap  :vmapclear         .        X       .
  118. :omap  :onoremap  :ounmap  :omapclear         .        .       X
  119.  
  120.                       Insert Command-line        ~
  121. :map!  :noremap!  :unmap!  :mapclear!         X           X
  122. :imap  :inoremap  :iunmap  :imapclear         X           .
  123. :cmap  :cnoremap  :cunmap  :cmapclear         .           X
  124.  
  125. The original Vi did not have separate mappings for
  126. Normal/Visual/Operator-pending mode and for Insert/Command-line mode.
  127. Therefore the ":map" and ":map!" commands enter and display mappings for
  128. several modes.  In Vim you can use the ":nmap", ":vmap", ":omap", ":cmap" and
  129. ":imap" commands to enter mappings for each mode separately.
  130.  
  131. To enter a mapping for Normal and Visual mode, but not Operator-pending mode,
  132. first define it for all three modes, then unmap it for Operator-pending mode:
  133.     :map    xx something-difficult
  134.     :ounmap xx
  135. Likewise for a mapping for Visual and Operator-pending mode or Normal and
  136. Operator-pending mode.
  137.  
  138.                             *map-listing*
  139. When listing mappings the characters in the first two columns are:
  140.  
  141.     CHAR        MODE    ~
  142.     <Space>        Normal, Visual and Operator-pending
  143.      n        Normal
  144.      v        Visual
  145.      o        Operator-pending
  146.      !        Insert and Command-line
  147.      i        Insert
  148.      c        Command-line
  149.  
  150. A "*" just before the {rhs} indicates that it is not remappable.
  151.  
  152. Everything from the first non-blank after {lhs} up to the end of the line
  153. (or '|') is considered to be part of {rhs}.  This allows the {rhs} to end
  154. with a space.
  155.  
  156. Note: When using mappings for Visual mode, you can use the "'<" mark, which
  157. is the start of the last selected Visual area in the current buffer |'<|.
  158.  
  159.                             *map_backslash*
  160. Note that only CTRL-V is mentioned here as a special character for mappings
  161. and abbreviations.  When 'cpoptions' does not contain 'B', a backslash can
  162. also be used like CTRL-V.  The <> notation can be fully used then |<>|.  But
  163. you cannot use "<C-V>" like CTRL-V to escape the special meaning of what
  164. follows.
  165.  
  166. To map a backslash, or use a backslash literally in the {rhs}, the special
  167. sequence "<Bslash>" can be used.  This avoids the need to double backslashes
  168. when using nested mappings.
  169.  
  170.                             *map_CTRL_C*
  171. It's not possible to use a CTRL-C in the {lhs}.  You just can't map CTRL-C.
  172. The reason is that CTRL-C must always be available to break a running command.
  173.  
  174.                             *map_space_in_lhs*
  175. To include a space in {lhs} precede it with a CTRL-V (type two CTRL-Vs for
  176. each space).
  177.                             *map_space_in_rhs*
  178. If you want a {rhs} that starts with a space, use "<Space>".  To be fully Vi
  179. compatible (but unreadable) don't use the |<>| notation, precede {rhs} with a
  180. single CTRL-V (you have to type CTRL-V two times).
  181.                             *map_empty_rhs*
  182. You can create an empty {rhs} by typing nothing after a single CTRL-V (you
  183. have to type CTRL-V two times).  Unfortunately, you cannot do this in a vimrc
  184. file.
  185.                             *<Nop>*
  186. A easier way to get a mapping that doesn't produce anything, is to use "<Nop>"
  187. for the {rhs}.  This only works when the |<>| notation is enabled.  For
  188. example, to make sure that function key 8 does nothing at all:
  189. >    :map  <F8>  <Nop>
  190. >    :map! <F8>  <Nop>
  191.  
  192.                             *map-comments*
  193. It is not possible to put a comment after these commands, because the '"'
  194. character is considered to be part of the {lhs} or {rhs}.
  195.  
  196.                             *map_bar*
  197. Since the '|' character is used to separate a map command from the next
  198. command, you will have to do something special to include  a '|' in {rhs}.
  199. There are three methods:
  200.    use         works when               example    ~
  201.    <Bar>     '<' is not in 'cpoptions'       :map _l :!ls <Bar> more^M
  202.    \|         'b' is not in 'cpoptions'       :map _l :!ls \| more^M
  203.    ^V|         always, in Vim and Vi       :map _l :!ls ^V| more^M
  204.  
  205. (here ^V stands for CTRL-V; to get one CTRL-V you have to type it twice; you
  206. cannot use the <> notation "<C-V>" here).
  207.  
  208. All three work when you use the default setting for 'cpoptions'.
  209.  
  210. When 'b' is present in 'cpoptions', "\|" will be recognized as a mapping
  211. ending in a '\' and then another command.  This is Vi compatible, but
  212. illogical when compared to other commands.
  213.  
  214.                             *map_return*
  215. When you have a mapping that contains an Ex command, you need to put a line
  216. terminator after it to have it executed.  The use of <CR> is recommended for
  217. this (see |<>|).  Example:
  218. >  :map  _ls  :!ls -l %<CR>:echo "the end"<CR>
  219.  
  220. To avoid mapping of the characters you type in insert or Command-line mode,
  221. type a CTRL-V first.  The mapping in Insert mode is disabled if the 'paste'
  222. option is on.
  223.  
  224. Note that when an error is encountered (that causes an error message) the rest
  225. of the mapping is not executed.  This is Vi-compatible.
  226.  
  227. Note that the second character (argument) of the commands @zZtTfF[]rm'`"v
  228. and CTRL-X is not mapped.  This was done to be able to use all the named
  229. registers and marks, even when the command with the same name has been
  230. mapped.
  231.  
  232.                             *map-which-keys*
  233. If you are going to map something, you will need to choose which key(s) to use
  234. for the {lhs}.  You will have to avoid keys that are used for Vim commands,
  235. otherwise you would not be able to use those commands anymore.  Here are a few
  236. suggestions:
  237. - Function keys <F2>, <F3>, etc..  Also the shifted function keys.  Note that
  238.   <F1> is already used for the help command.
  239. - Meta-keys (with the ALT key pressed).
  240. - Use the "_" character and then any other character.  The "_" command does
  241.   exist in Vim (see |_|), but you probably never use it.
  242. - Use a key that is a synonym for another command.  For example: CTRL-P and
  243.   CTRL-N.  Use an extra character to allow more mappings.
  244.  
  245.                             *map-examples*
  246. A few examples (given as you type them, for "<CR>" you type four characters;
  247. the '<' flag must not be present in 'cpoptions' for this to work).
  248.  
  249. >  :map <F3>  o#include
  250. >  :map <M-g> /foo<CR>cwbar<Esc>
  251. >  :map _x    d/END/e<CR>
  252. >  :map! qq   quadrillion questions
  253.  
  254.                             *map-typing*
  255. Vim will compare what you type with the start of a mapped sequence.  If there
  256. is an incomplete match, it will get more characters until there either is a
  257. complete match or until there is no match at all.  Example: If you map! "qq",
  258. the first 'q' will not appear on the screen until you type another
  259. character.  This is because Vim cannot know if the next character will be a
  260. 'q' or not.  If the 'timeout' option is on (which is the default) Vim will
  261. only wait for one second (or as long as specified with the 'timeoutlen'
  262. option).  After that it assumes that the 'q' is to be interpreted as such.  If
  263. type slowly, or your system is slow, reset the 'timeout' option.  Then you
  264. might want to set the 'ttimeout' option.
  265.  
  266.                             *map-keys-fails*
  267. There is one situation where key codes might not be recognized:
  268. - Vim can only read part of the key code.  Mostly this is only the first
  269.   character.  This happens on some Unix versions in an xterm.
  270. - The key code is after character(s) that are mapped.  E.g., "<F1><F1>" or
  271.   "g<F1>".
  272. The result is that the key code is not recognized in this situation, and the
  273. mapping fails.
  274. There are two actions needed to avoid this problem:
  275. - Remove the 'K' flag from 'cpoptions'.  This will make Vim wait for the rest
  276.   of the characters of the function key.
  277. - When using <F1> to <F4> the actual key code generated may correspond to
  278.   <xF1> to <xF4>.  There are mappings from <xF1> to <F1>, <xF2> to <F2>, etc.,
  279.   but these are not recognized after another half a mapping.  Make sure the
  280.   key codes for <F1> to <F4> are correct:
  281. >    :set <F1>=<type CTRL-V><type F1>
  282.   Type the <F1> as four characters.  The part after the "=" must be done with
  283.   the actual keys, not the literal text.
  284. Another solution is to use the actual key code in the mapping for the second
  285. special key:
  286. >    :map <F1><Esc>OP :echo "yes"<CR>
  287. Don't type a real <Esc>, Vim will recognize the key code and replace it with
  288. <F1> anyway.
  289.  
  290.                         *recursive_mapping*
  291. If you include the {lhs} in the {rhs} you have a recursive mapping.  When
  292. {lhs} is typed, it will be replaced with {rhs}.  When the {lhs} which is
  293. included in {rhs} is encountered it will be replaced with {rhs}, and so on.
  294. This makes it possible to repeat a command an infinite number of times.  The
  295. only problem is that the only way to stop this is by causing an error.  The
  296. macros to solve a maze uses this, look there for an example.  There is one
  297. exception: If the {rhs} starts with {lhs}, the first character is not mapped
  298. again (this is Vi compatible).
  299. For example:
  300. >  :map ab abcd
  301. will execute the "a" command and insert "bcd" in the text.  The "ab" in the
  302. {rhs} will not be mapped again.
  303.  
  304. If you want to exchange the meaning of two keys you should use the :noremap
  305. command.  For example:
  306. >  :noremap k j
  307. >  :noremap j k
  308. This will exchange the cursor up and down commands.
  309.  
  310. With the normal :map command, when the 'remap' option is on, mapping takes
  311. place until the text is found not to be a part of a {lhs}.  For example, if
  312. you use:
  313. >  :map x y
  314. >  :map y x
  315. Vim will replace x with y, and then y with x, etc.  When this has happened
  316. 'maxmapdepth' times (default 1000), Vim will give the error message
  317. "recursive mapping".
  318.  
  319. See the file "index" for keys that are not used and thus can be mapped
  320. without losing any builtin function.  I suggest you use function keys,
  321. and meta-keys.  If you are prepared to lose a command that you hardly ever use
  322. you can make mappings that start with '_' or '-'.  You can also use
  323. ":help {key}^D" to find out if a key is used for some command.  ({key} is the
  324. specific key you want to find out about, ^D is CTRL-D).
  325.  
  326. If you include an undo command inside a mapped sequence, this will bring the
  327. text back in the state before executing the macro.  This is compatible with
  328. the original Vi, as long as there is only one undo command in the mapped
  329. sequence (having two undo commands in a mapped sequence did not make sense
  330. in the original Vi, you would get back the text before the first undo).
  331.  
  332. There are three ways to map a special key:
  333. 1. The Vi-compatible method: Map the key code.  Often this is a sequence that
  334.    starts with <Esc>.  To enter a mapping like this you type ":map " and then
  335.    you have to type CTRL-V before hitting the function key.  Note that when
  336.    the key code for the key is in the termcap (the t_ options), it will
  337.    automatically be translated into the internal code and become the second
  338.    way of mapping (unless the 'k' flag is included in 'cpoptions').
  339. 2. The second method is to use the internal code for the function key.  To
  340.    enter such a mapping type CTRL-K and then hit the function key, or use
  341.    the form "#1", "#2", .. "#9", "#0", "<Up>", "<S-Down>", "<S-F7>", etc.
  342.    (see table of keys |key-notation|, all keys from <Up> can be used).  The
  343.    first ten function keys can be defined in two ways: Just the number, like
  344.    "#2", and with "<F>", like "<F2>".  Both stand for function key 2.  "#0"
  345.    refers to function key 10, defined with option 't_f10', which may be
  346.    function key zero on some keyboards.  The <> form cannot be used when
  347.    'cpoptions' includes the '<' flag.
  348. 3. Use the termcap entry, with the form <t_xx>, where "xx" is the name of the
  349.    termcap entry.  Any string entry can be used.  For example:
  350. >    :map <t_F3> G
  351.    Maps function key 13 to "G".  This does not work if 'cpoptions' includes
  352.    the '<' flag.
  353.  
  354. The advantage of the second and third method is that the mapping will work on
  355. different terminals without modification (the function key will be
  356. translated into the same internal code or the actual key code, no matter what
  357. terminal you are using.  The termcap must be correct for this to work, and you
  358. must use the same mappings).
  359.  
  360. DETAIL: Vim first checks if a sequence from the keyboard is mapped.  If it
  361. isn't the terminal key codes are tried (see |terminal-options|).  If a
  362. terminal code is found it is replaced with the internal code.  Then the check
  363. for a mapping is done again (so you can map an internal code to something
  364. else).  What is written into the script file depends on what is recognized.
  365. If the terminal key code was recognized as a mapping the key code itself is
  366. written to the script file.  If it was recognized as a terminal code the
  367. internal code is written to the script file.
  368.  
  369. ==============================================================================
  370. 2. Abbreviations            *abbreviations* *Abbreviations*
  371.  
  372. Abbreviations are used in Insert mode, Replace mode and Command-line mode.
  373. If you enter a word that is an abbreviation, it is replaced with the word it
  374. stands for.  This can be used to save typing for often used long words.  And
  375. you can use it to automatically correct obvious spelling errors.
  376. Examples:
  377.  
  378.     :iab ms MicroSoft
  379.     :iab tihs this
  380.  
  381. There are three types of abbreviations:
  382.  
  383. full-id      The "full-id" type consists entirely of keyword characters (letters
  384.       and characters from 'iskeyword' option).  This is the most common
  385.       abbreviation.
  386.  
  387.       Examples: "foo", "g3", "-1"
  388.  
  389. end-id      The "end-id" type ends in a keyword character, but all the other
  390.       characters are not keyword characters.
  391.  
  392.       Examples: "#i", "..f", "$/7"
  393.  
  394. non-id      The "non-id" type ends in a non-keyword character, the other
  395.       characters may be of any type, excluding space and Tab.  {this type
  396.       is not supported by Vi}
  397.  
  398.       Examples: "def#", "4/7$"
  399.  
  400. Examples of strings that cannot be abbreviations: "a.b", "#def", "a b", "_$r"
  401.  
  402. An abbreviation is only recognized when you type a non-keyword character.
  403. This can also be the <Esc> that ends insert mode or the <CR> that ends a
  404. command.  The non-keyword character which ends the abbreviation is inserted
  405. after the expanded abbreviation.  An exception to this is the character <C-]>,
  406. which is used to expand an abbreviation without inserting any extra
  407. characters.
  408.  
  409. Example:
  410. >   :ab hh    hello
  411.         "hh<Space>" is expanded to "hello<Space>"
  412.         "hh<C-]>" is expanded to "hello"
  413.  
  414. The characters before the cursor must match the abbreviation.  Each type has
  415. an additional rule:
  416.  
  417. full-id      In front of the match is a non-keyword character, or this is where
  418.       the line or insertion starts.  Exception: When the abbreviation is
  419.       only one character, it is not recognized if there is a non-keyword
  420.       character in front of it, other than a space or a <Tab>.
  421.  
  422. end-id      In front of the match is a keyword character, or a space or a <Tab>,
  423.       or this is where the line or insertion starts.
  424.  
  425. non-id      In front of the match is a space, <Tab> or the start of the line or
  426.       the insertion.
  427.  
  428. Examples: ({CURSOR} is where you type a non-keyword character)
  429. >  :ab foo   four old otters
  430.         " foo{CURSOR}"      is expanded to " four old otters"
  431.         " foobar{CURSOR}" is not expanded
  432.         "barfoo{CURSOR}"  is not expanded
  433.  
  434. >  :ab #i #include
  435.         "#i{CURSOR}"      is expanded to "#include"
  436.         ">#i{CURSOR}"      is not expanded
  437.  
  438. >  :ab ;; <endofline>"
  439.         "test;;"      is not expanded
  440.         "test ;;"      is expanded to "test <endofline>"
  441.  
  442. To avoid the abbreviation in insert mode: Type part of the abbreviation, exit
  443. insert mode with <Esc>, re-enter insert mode with "a" and type the rest.  Or
  444. type CTRL-V before the character after the abbreviation.
  445. To avoid the abbreviation in Command-line mode: Type CTRL-V twice somewhere in
  446. the abbreviation to avoid it to be replaced.  A CTRL-V in front of a normal
  447. character is mostly ignored otherwise.
  448.  
  449. There are no default abbreviations.
  450.  
  451. Abbreviations are never recursive.  You can use ":ab f f-o-o" without any
  452. problem.  But abbreviations can be mapped.  {some versions of Vi support
  453. recursive abbreviations, for no apparent reason}
  454.  
  455. Abbreviations are disabled if the 'paste' option is on.
  456.  
  457.                         *:ab* *:abbreviate*
  458. :ab[breviate]        list all abbreviations.  The character in the first
  459.             column indicates the mode where the abbreviation is
  460.             used: 'i' for insert mode, 'c' for Command-line
  461.             mode, '!' for both.
  462.  
  463. :ab[breviate] {lhs}    list the abbreviations that start with {lhs}
  464.  
  465. :ab[breviate] {lhs} {rhs}
  466.             add abbreviation for {lhs} to {rhs}.  If {lhs} already
  467.             existed it is replaced with the new {rhs}.  {rhs} may
  468.             contain spaces.
  469.  
  470.                         *:una* *:unabbreviate*
  471. :una[bbreviate] {lhs}    remove abbreviation for {lhs} from the list
  472.  
  473.                         *:norea* *:noreabbrev*
  474. :norea[bbrev] [lhs] [rhs]
  475.             same as ":ab", but no remapping for this {rhs} {not
  476.             in Vi}
  477.  
  478.                         *:ca* *:cabbrev*
  479. :ca[bbrev] [lhs] [rhs]    same as ":ab", but for Command-line mode only.  {not
  480.             in Vi}
  481.  
  482.                         *:cuna* *:cunabbrev*
  483. :cuna[bbrev] {lhs}    same as ":una", but for Command-line mode only.  {not
  484.             in Vi}
  485.  
  486.                         *:cnorea* *:cnoreabbrev*
  487. :cnorea[bbrev] [lhs] [rhs]
  488.             same as ":ab", but for Command-line mode only and no
  489.             remapping for this {rhs} {not in Vi}
  490.  
  491.                         *:ia* *:iabbrev*
  492. :ia[bbrev] [lhs] [rhs]    same as ":ab", but for Insert mode only.  {not in Vi}
  493.  
  494.                         *:iuna* *:iunabbrev*
  495. :iuna[bbrev] {lhs}    same as ":una", but for insert mode only.  {not in
  496.             Vi}
  497.  
  498.                         *:inorea* *:inoreabbrev*
  499. :inorea[bbrev] [lhs] [rhs]
  500.             same as ":ab", but for Insert mode only and no
  501.             remapping for this {rhs} {not in Vi}
  502.  
  503.                             *:abc* *:abclear*
  504. :abc[lear]        Remove all abbreviations.  {not in Vi}
  505.  
  506.                             *:iabc* *:iabclear*
  507. :iabc[lear]        Remove all abbreviations for Insert mode.  {not in Vi}
  508.  
  509.                             *:cabc* *:cabclear*
  510. :cabc[lear]        Remove all abbreviations for Command-line mode.  {not
  511.             in Vi}
  512.  
  513.                             *using_CTRL-V*
  514. It is possible to use special characters in the rhs of an abbreviation.
  515. CTRL-V has to be used to avoid the special meaning of most non printable
  516. characters.  How many CTRL-Vs need to be typed depends on how you enter the
  517. abbreviation.  This also applies to mappings.  Let's use an example here.
  518.  
  519. Suppose you want to abbreviate "esc" to enter an <Esc> character.  When you
  520. type the ":ab" command in Vim, you have to enter this: (here ^V is a CTRL-V
  521. and ^[ is <Esc>)
  522.  
  523. You type:   ab esc ^V^V^V^V^V^[
  524.  
  525.     All keyboard input is subjected to ^V quote interpretation, so
  526.     the first, third, and fifth ^V  characters simply allow the second,
  527.     and fourth ^Vs, and the ^[, to be entered into the command-line.
  528.  
  529. You see:    ab esc ^V^V^[
  530.  
  531.     The command-line contains two actual ^Vs before the ^[.  This is
  532.     how it should appear in your .exrc file, if you choose to go that
  533.     route.  The first ^V is there to quote the second ^V; the :ab
  534.     command uses ^V as its own quote character, so you can include quoted
  535.     whitespace or the | character in the abbreviation.   The :ab command
  536.     doesn't do anything special with the ^[ character, so it doesn't need
  537.     to be quoted.  (Although quoting isn't harmful; that's why typing 7
  538.     [but not 8!] ^Vs works.)
  539.  
  540. Stored as:  esc     ^V^[
  541.  
  542.     After parsing, the abbreviation's short form ("esc") and long form
  543.     (the two characters "^V^[") are stored in the abbreviation table.
  544.     If you give the :ab command with no arguments, this is how the
  545.     abbreviation will be displayed.
  546.  
  547.     Later, when the abbreviation is expanded because the user typed in
  548.     the word "esc", the long form is subjected to the same type of
  549.     ^V interpretation as keyboard input.  So the ^V protects the ^[
  550.     character from being interpreted as the "exit input-mode" character.
  551.     Instead, the ^[ is inserted into the text.
  552.  
  553. Expands to: ^[
  554.  
  555. [example given by Steve Kirkendall]
  556.  
  557. ==============================================================================
  558. 3. User-defined commands                *user-commands*
  559.  
  560. It is possible to define your own ex commands. A user-defined command can act
  561. just like a built-in command (it can have a range or arguments, arguments can
  562. be completed as filenames or buffer names, etc), except that when the command
  563. is executed, it is transformed into a normal ex command and then executed.
  564.  
  565. All user defined commands must start with an uppercase letter, to avoid
  566. confusion with builtin commands. (There are a few builtin commands, notably
  567. :Next and :Print, which do start with an uppercase letter.  The builtin will
  568. always take precedence in these cases).  The other characters of the user
  569. command can be uppercase letters, lowercase letters or digits.  When using
  570. digits, note that other commands that take a numeric argument may become
  571. ambiguous.  For example, the command ":Cc2" could be the user command ":Cc2"
  572. without an argument, or the command ":Cc" with argument "2".  It is advised to
  573. put a space between the command name and the argument to avoid these problems.
  574.  
  575. When using a user-defined command, the command can be abbreviated. However, if
  576. an abbreviation is not unique, an error will be issued. Furthermore, a
  577. built-in command will always take precedence.
  578.  
  579. Example:
  580. >    :command Rename ...
  581. >    :command Renumber ...
  582. >    :Rena                " Means "Rename"
  583. >    :Renu                " Means "Renumber"
  584. >    :Ren                " Error - ambiguous
  585. >    :command Paste ...
  586. >    :P                " The built-in :Print
  587.  
  588. It is recommended that full names for user-defined commands are used in
  589. scripts.
  590.  
  591. :com[mand]                        *:com* *:command*
  592.             List all user-defined commands. When listing commands,
  593.             the characters in the first two columns are
  594.                 !    Command has the -bang attribute
  595.                 "    Command has the -register attribute
  596.             (see below for details on attributes)
  597.  
  598. :com[mand] {cmd}    List the user-defined commands that start with {cmd}
  599.  
  600. :com[mand][!] [{attr}...] {cmd} {rep}
  601.             Define a user command.  The name of the command is
  602.             {cmd} and its replacement text is {rep}. The command's
  603.             attributes (see below) are {attr}. If the command
  604.             already exists, an error is reported, unless a ! is
  605.             specified, in which case the command is redefined.
  606.  
  607. :delc[ommand] {cmd}                    *:delc* *:delcommand*
  608.             Delete the user-defined command {cmd}.
  609.  
  610. :comc[lear]                        *:comc* *:comclear*
  611.             Delete all user-defined commands.
  612.  
  613. Command attributes
  614.  
  615. User-defined commands are treated by Vim just like any other ex commands. They
  616. can have arguments, or have a range specified. Arguments are subject to
  617. completion as filenames, buffers, etc. Exactly how this works depends upon the
  618. command's attributes, which are specified when the command is defined.
  619.  
  620. There are a number of attributes, split into four categories: argument
  621. handling, completion behavior, range handling, and special cases. The
  622. attributes are described below, by category.
  623.  
  624. Argument handling
  625.  
  626. By default, a user defined command will take no arguments (and an error is
  627. reported if any are supplied). However, it is possible to specify that the
  628. command can take arguments, using the -nargs attribute. Valid cases are:
  629.  
  630.     -nargs=0    No arguments are allowed (the default)
  631.     -nargs=1    Exactly one argument is required
  632.     -nargs=*    Any number of arguments are allowed (0, 1, or many)
  633.     -nargs=?    0 or 1 arguments are allowed
  634.     -nargs=+    Arguments must be supplied, but any number are allowed
  635.  
  636. Arguments are considered to be separated by (unescaped) spaces in this
  637. context.
  638.  
  639. Completion behavior
  640.  
  641. By default, the arguments of user defined commands do not undergo completion.
  642. However, by specifying one or the other of the following attributes, argument
  643. completion can be enabled:
  644.  
  645.     -complete=augroup    autocmd groups
  646.     -complete=buffer    buffer names
  647.     -complete=command    Ex command (and arguments)
  648.     -complete=dir        directory names
  649.     -complete=event        autocommand events
  650.     -complete=file        file and directory names
  651.     -complete=help        help subjects
  652.     -complete=highlight    highlight groups
  653.     -complete=menu        menus
  654.     -complete=option    options
  655.     -complete=tag        tags
  656.     -complete=tag_listfiles    tags, file names are shown when CTRL-D is hit
  657.     -complete=var        user variables
  658.  
  659. Range handling
  660.  
  661. By default, user-defined commands do not accept a line number range. However,
  662. it is possible to specify that the command does take a range (the -range
  663. attribute), or that it takes an arbitrary count value, either in the line
  664. number position (-range=N, like the |:split| command) or as a "count"
  665. argument (-count=N, like the |:Next| command). Possible attributes are:
  666.  
  667.     -range        Range allowed, default is current line
  668.     -range=%    Range allowed, default is whole file (1,$)
  669.     -range=N    A count (default N) which is specified in the line
  670.             number position (like |:split|)
  671.     -count=N    A count (default N) which is specified either in the line
  672.             number position, or as an initial argument (like |:Next|)
  673.             Specifying -count (without a default) acts like -count=0
  674.  
  675. Note that -range=N and -count=N are mutually exclusive - only one should be
  676. specified.
  677.  
  678. Special cases
  679.  
  680. There are some special cases as well:
  681.  
  682.     -bang        The command can take a ! modifier (like :q or :w)
  683.     -register   The first argument to the command can be an optional
  684.             register name (like :del, :put, :yank).
  685.  
  686. In the cases of the -count and -register attributes, if the optional argument
  687. is supplied, it is removed from the argument list and is available to the
  688. replacement text separately.
  689.  
  690. Replacement text
  691.  
  692. The replacement text for a user defined command is scanned for special escape
  693. sequences, using <...> notation. Escape sequences are replaced with values
  694. from the entered command line, and all other text is copied unchanged. The
  695. resulting string is executed as an Ex command. If the initial < of an escape
  696. sequence is preceded by a backslash, the sequence is copied unchanged.
  697.  
  698. The valid escape sequences are
  699.  
  700.                         *<line1>*
  701.     <line1>    The starting line of the command range.
  702.                         *<line2>*
  703.     <line2>    The final line of the command range.
  704.                         *<count>*
  705.     <count>    Any count supplied (as described for the '-range'
  706.         and '-count' attributes).
  707.                         *<bang>*
  708.     <bang>    (See the '-bang' attribute) Expands to a ! if the
  709.         command was executed with a ! modifier, otherwise
  710.         expands to nothing.
  711.                         *<reg>* *<register>*
  712.     <reg>    (See the '-register' attribute) The optional register,
  713.         if specified. Otherwise, expands to nothing. <register>
  714.         is a synonym for this.
  715.                         *<args>*
  716.     <args>    The command arguments, exactly as supplied (but as
  717.         noted above, any count or register can consume some
  718.         of the arguments, which are then not part of <args>).
  719.     <lt>    A single '<' (Less-Then) character.  This is needed if you
  720.         want to get a literal copy of one of these escape sequences
  721.         into the expansion - for example, to get <bang>, use
  722.         <lt>bang>.
  723.  
  724. If the first two characters of an escape sequence are "q-" (for example,
  725. <q-args>) then the value is quoted in such a way as to make it a valid value
  726. for use in an expression.  This uses the argument as one single value.
  727.  
  728. To allow commands to pass their arguments on to a user-defined function, there
  729. is a special form <f-args> ("function args"). This splits the command
  730. arguments at spaces, quotes each argument individually, and the <f-args>
  731. sequence is replaced by the comma-separated list of quoted arguments.  See the
  732. Mycmd example below.
  733.  
  734. Examples
  735.  
  736. >   " Delete everything after here to the end
  737. >   :com Ddel +,$d
  738.  
  739. >   " Rename the current buffer
  740. >   :com -nargs=1 -bang -complete=file Ren f <args>|w<bang>
  741.  
  742. >   " Replace a range with the contents of a file
  743. >   " (Enter this all as one line)
  744. >   :com -range -nargs=1 -complete=file
  745. >     Replace <line1>-pu_|<line1>,<line2>d|r <args>|<line1>d
  746.  
  747. >   " Call a user function (example of <f-args>)
  748. >   :com -nargs=* Mycmd call Myfunc(<f-args>)
  749.  
  750. When executed as:
  751. >    :Mycmd arg1 arg2
  752. This will invoke:
  753. >    :call Myfunc("arg1","arg2")
  754.  
  755. >   " A more substantial example
  756. >   :function Allargs(command)
  757. >   :    let i = 0
  758. >   :    while i < argc()
  759. >   :       if filereadable(argv(i))
  760. >   :        execute "e " . argv(i)
  761. >   :         execute a:command
  762. >   :      endif
  763. >   :      let i = i + 1
  764. >   :   endwhile
  765. >   :endfunction
  766. >   :command -nargs=+ -complete=command Allargs call Allargs(<q-args>)
  767.  
  768. The command Allargs takes any Vim command(s) as argument and executes it on all
  769. files in the argument list.  Usage example (note use of the "e" flag to ignore
  770. errors and the "update" command to write modified buffers):
  771. >    :Allargs %s/foo/bar/ge|update
  772. This will invoke:
  773. >    :call Allargs("%s/foo/bar/ge|update")
  774.  
  775.  vim:tw=78:ts=8:sw=8:
  776.