📄 map.txt
字号:
*map.txt* For Vim version 5.8. Last change: 2001 Jan 30 VIM REFERENCE MANUAL by Bram MoolenaarKey mapping and abbreviations.1. Key mapping |key-mapping|2. Abbreviations |abbreviations|3. User-defined commands |user-commands|==============================================================================1. Key mapping *key-mapping* *mapping* *macro*There are commands to enter new mappings, remove mappings and list mappings.See |map-overview| for the various forms of "map" and their relationships withmodes.: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*: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*: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*: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*: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]: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*: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 ofcharacters. You can use this to put command sequences under function keys,translate one key into another, etc. See |:mkexrc| for how to save andrestore the current mappings.There are five sets of mappings- For Normal mode: When typing commands.- For Visual mode: When typing commands while the Visual area is highlighted.- For Operator-pending mode: When an operator is pending (after "d", "y", "c", etc.).- For Insert mode. These are also used in Replace mode.- For Command-line mode: When entering a ":" or "/" command.There are no separate mappings for Select mode. The same as for Visual modeare used |Select-mode-mapping|. *map-overview* *map-modes*Overview of which map command works in which mode: commands: modes: ~ Normal Visual Operator-pending ~:map :noremap :unmap :mapclear X X X:nmap :nnoremap :nunmap :nmapclear X . .:vmap :vnoremap :vunmap :vmapclear . X .:omap :onoremap :ounmap :omapclear . . X Insert Command-line ~:map! :noremap! :unmap! :mapclear! X X:imap :inoremap :iunmap :imapclear X .:cmap :cnoremap :cunmap :cmapclear . XThe original Vi did not have separate mappings forNormal/Visual/Operator-pending mode and for Insert/Command-line mode.Therefore the ":map" and ":map!" commands enter and display mappings forseveral modes. In Vim you can use the ":nmap", ":vmap", ":omap", ":cmap" and":imap" commands to enter mappings for each mode separately.To enter a mapping for Normal and Visual mode, but not Operator-pending mode,first define it for all three modes, then unmap it for Operator-pending mode: :map xx something-difficult :ounmap xxLikewise for a mapping for Visual and Operator-pending mode or Normal andOperator-pending mode. *map-listing*When listing mappings the characters in the first two columns are: CHAR MODE ~ <Space> Normal, Visual and Operator-pending n Normal v Visual o Operator-pending ! Insert and Command-line i Insert c Command-lineA "*" just before the {rhs} indicates that it is not remappable.Everything from the first non-blank after {lhs} up to the end of the line(or '|') is considered to be part of {rhs}. This allows the {rhs} to endwith a space.Note: When using mappings for Visual mode, you can use the "'<" mark, whichis the start of the last selected Visual area in the current buffer |'<|. *map_backslash*Note that only CTRL-V is mentioned here as a special character for mappingsand abbreviations. When 'cpoptions' does not contain 'B', a backslash canalso be used like CTRL-V. The <> notation can be fully used then |<>|. Butyou cannot use "<C-V>" like CTRL-V to escape the special meaning of whatfollows.To map a backslash, or use a backslash literally in the {rhs}, the specialsequence "<Bslash>" can be used. This avoids the need to double backslasheswhen using nested mappings. *map_CTRL_C*It's not possible to use a CTRL-C in the {lhs}. You just can't map CTRL-C.The reason is that CTRL-C must always be available to break a running command. *map_space_in_lhs*To include a space in {lhs} precede it with a CTRL-V (type two CTRL-Vs foreach space). *map_space_in_rhs*If you want a {rhs} that starts with a space, use "<Space>". To be fully Vicompatible (but unreadable) don't use the |<>| notation, precede {rhs} with asingle CTRL-V (you have to type CTRL-V two times). *map_empty_rhs*You can create an empty {rhs} by typing nothing after a single CTRL-V (youhave to type CTRL-V two times). Unfortunately, you cannot do this in a vimrcfile. *<Nop>*A easier way to get a mapping that doesn't produce anything, is to use "<Nop>"for the {rhs}. This only works when the |<>| notation is enabled. Forexample, to make sure that function key 8 does nothing at all:> :map <F8> <Nop>> :map! <F8> <Nop> *map-comments*It is not possible to put a comment after these commands, because the '"'character is considered to be part of the {lhs} or {rhs}. *map_bar*Since the '|' character is used to separate a map command from the nextcommand, you will have to do something special to include a '|' in {rhs}.There are three methods: use works when example ~ <Bar> '<' is not in 'cpoptions' :map _l :!ls <Bar> more^M \| 'b' is not in 'cpoptions' :map _l :!ls \| more^M ^V| always, in Vim and Vi :map _l :!ls ^V| more^M(here ^V stands for CTRL-V; to get one CTRL-V you have to type it twice; youcannot use the <> notation "<C-V>" here).All three work when you use the default setting for 'cpoptions'.When 'b' is present in 'cpoptions', "\|" will be recognized as a mappingending in a '\' and then another command. This is Vi compatible, butillogical when compared to other commands. *map_return*When you have a mapping that contains an Ex command, you need to put a lineterminator after it to have it executed. The use of <CR> is recommended forthis (see |<>|). Example:> :map _ls :!ls -l %<CR>:echo "the end"<CR>To avoid mapping of the characters you type in insert or Command-line mode,type a CTRL-V first. The mapping in Insert mode is disabled if the 'paste'option is on.Note that when an error is encountered (that causes an error message) the restof the mapping is not executed. This is Vi-compatible.Note that the second character (argument) of the commands @zZtTfF[]rm'`"vand CTRL-X is not mapped. This was done to be able to use all the namedregisters and marks, even when the command with the same name has beenmapped. *map-which-keys*If you are going to map something, you will need to choose which key(s) to usefor the {lhs}. You will have to avoid keys that are used for Vim commands,otherwise you would not be able to use those commands anymore. Here are a fewsuggestions:- Function keys <F2>, <F3>, etc.. Also the shifted function keys <S-F1>, <S-F2>, etc. Note that <F1> is already used for the help command.- Meta-keys (with the ALT key pressed).- Use the '_' or ',' character and then any other character. The "_" and "," commands do exist in Vim (see |_| and |,|), but you probably never use them.- Use a key that is a synonym for another command. For example: CTRL-P and CTRL-N. Use an extra character to allow more mappings.See the file "index" for keys that are not used and thus can be mapped withoutlosing any builtin function. You can also use ":help {key}^D" to find out ifa key is used for some command. ({key} is the specific key you want to findout about, ^D is CTRL-D). *map-examples*A few examples (given as you type them, for "<CR>" you type four characters;the '<' flag must not be present in 'cpoptions' for this to work).> :map <F3> o#include> :map <M-g> /foo<CR>cwbar<Esc>> :map _x d/END/e<CR>> :map! qq quadrillion questions *map-typing*Vim will compare what you type with the start of a mapped sequence. If thereis an incomplete match, it will get more characters until there either is acomplete match or until there is no match at all. Example: If you map! "qq",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -