*map.txt* For Vim version 7.0aa. Last change: 2004 May 21 VIM REFERENCE MANUAL by Bram Moolenaar Key mapping, abbreviations and user-defined commands. This subject is introduced in sections |05.3|, |24.7| and |40.1| of the user manual. 1. Key mapping |key-mapping| 2. Abbreviations |abbreviations| 3. Local mappings and functions |script-local| 4. User-defined commands |user-commands| ============================================================================== 1. Key mapping *key-mapping* *mapping* *macro* Key mapping is used to change the meaning of typed keys. The most common use is to define a sequence commands for a function key. Example: > :map a=strftime("%c") This appends the current date and time after the cursor. (in <> notation |<>|) There are commands to enter new mappings, remove mappings and list mappings. See |map-overview| for the various forms of "map" and their relationships with modes. {lhs} means left-hand-side *{lhs}* {rhs} means right-hand-side *{rhs}* :map {lhs} {rhs} *:map* :nm[ap] {lhs} {rhs} *:nm* *:nmap* :vm[ap] {lhs} {rhs} *:vm* *:vmap* :om[ap] {lhs} {rhs} *:om* *:omap* :map! {lhs} {rhs} *:map!* :im[ap] {lhs} {rhs} *:im* *:imap* :lm[ap] {lhs} {rhs} *:lm* *:lmap* :cm[ap] {lhs} {rhs} *:cm* *:cmap* Map the key sequence {lhs} to {rhs} for the modes where the map command applies. The result, including {rhs}, is then further scanned for mappings. This allows for nested and recursive use of mappings. :no[remap] {lhs} {rhs} *:no* *:noremap* :nn[oremap] {lhs} {rhs} *:nn* *:nnoremap* :vn[oremap] {lhs} {rhs} *:vn* *:vnoremap* :ono[remap] {lhs} {rhs} *:ono* *:onoremap* :no[remap]! {lhs} {rhs} *:no!* *:noremap!* :ino[remap] {lhs} {rhs} *:ino* *:inoremap* :ln[oremap] {lhs} {rhs} *:ln* *:lnoremap* :cno[remap] {lhs} {rhs} *:cno* *:cnoremap* Map the key sequence {lhs} to {rhs} for the modes where the map command applies. Disallow mapping of {rhs}, to avoid nested and recursive mappings. Often used to redefine a command. {not in Vi} :unm[ap] {lhs} *:unm* *:unmap* :nun[map] {lhs} *:nun* *:nunmap* :vu[nmap] {lhs} *:vu* *:vunmap* :ou[nmap] {lhs} *:ou* *:ounmap* :unm[ap]! {lhs} *:unm!* *:unmap!* :iu[nmap] {lhs} *:iu* *:iunmap* :lu[nmap] {lhs} *:lu* *:lunmap* :cu[nmap] {lhs} *:cu* *:cunmap* Remove the mapping of {lhs} for the modes where the map command applies. The mapping may remain defined for other modes where it applies. Note: Trailing spaces are included in the {lhs}. This unmap does NOT work: > :map @@ foo :unmap @@ | print :mapc[lear] *:mapc* *:mapclear* :nmapc[lear] *:nmapc* *:nmapclear* :vmapc[lear] *:vmapc* *:vmapclear* :omapc[lear] *:omapc* *:omapclear* :mapc[lear]! *:mapc!* *:mapclear!* :imapc[lear] *:imapc* *:imapclear* :lmapc[lear] *:lmapc* *:lmapclear* :cmapc[lear] *:cmapc* *:cmapclear* Remove ALL mappings for the modes where the map command applies. {not in Vi} Warning: This also removes the default mappings. :map :nm[ap] :vm[ap] :om[ap] :map! :im[ap] :lm[ap] :cm[ap] List all key mappings for the modes where the map command applies. Note that ":map" and ":map!" are used most often, because they include the other modes. :map {lhs} *:map_l* :nm[ap] {lhs} *:nmap_l* :vm[ap] {lhs} *:vmap_l* :om[ap] {lhs} *:omap_l* :map! {lhs} *:map_l!* :im[ap] {lhs} *:imap_l* :lm[ap] {lhs} *:lmap_l* :cm[ap] {lhs} *:cmap_l* List the key mappings for the key sequences starting with {lhs} in the modes where the map command applies. {not in Vi} These commands are used to map a key or key sequence to a string of characters. You can use this to put command sequences under function keys, translate one key into another, etc. See |:mkexrc| for how to save and restore the current mappings. *:map-local* *:map-* *E224* *E225* If the first argument to one of these commands is "" it will apply to mappings locally to the current buffer only. Example: > :map ,w /[.,;] Then you can map ",w" to something else in another buffer: > :map ,w /[#&!] The local buffer mappings are used before the global ones. The "" argument can also be used to clear mappings: > :unmap ,w :mapclear Local mappings are also cleared when a buffer is deleted, but not when it is unloaded. Just like local option values. *:map-* *:map-silent* To define a mapping which will not be echoed on the command line, add "" as the first argument. Example: > :map ,h /Header The search string will not be echoed when using this mapping. Messages from the executed command are still given though. To shut them up too, add a ":silent" in the executed command: > :map ,h :exe ":silent normal /Header\r" Prompts will still be given, e.g., for inputdialog(). Using "" for an abbreviation is possible, but will cause redrawing of the command line to fail. *:map-