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 / vim54rt.sit / runtime / doc / map.txt < prev    next >
Encoding:
Text File  |  1999-08-14  |  30.5 KB  |  765 lines  |  [TEXT/ALFA]

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