This article explains the map mapping of vim clearly

Map mainly uses custom shortcut keys, such as map ab, which maps b to a key, so that when press a, execute b shortcut key;

One, map introduction

I often see map, nmap, imap, vmap, vnoremap, nunmap, nmapclear, etc. in the vim configuration file. What do they mean? The n, v, nore, un, etc. before the map have the following meanings:

1. nore-means non-recursive, map is recursively mapped by default

2. n —— means effective in normal mode

        For example: nmap <leader>s :wqa<CR> # means that after pressing the leader key (my setting is \) and the s key, execute the :wqa command, <CR> represents the carriage return

3. v —— means effective in visual mode

        For example: vmap <Cc> +y "means that in the visual mode, press ctrl+c to copy the selected content

4. i —— means effective in insert mode

5. c-means effective in command line mode

6. Un-followed by a key combination, which means to delete this mapping

       Such as: unvmap <Cc> "Delete mapping

7, clear-means clear shortcut key mapping

        Such as: mapclear, nmapclear, nnoremapclear, etc.

Some of the above mappings can be used in combination, such as:

    |COMMANDS                          MODES
:map   :noremap  :unmap           Normal, Visual, Select, Operator-pending
:nmap  :nnoremap :nunmap       Normal
:vmap  :vnoremap :vunmap        Visual and Select
:smap  :snoremap :sunmap        Select
:xmap  :xnoremap :xunmap        Visual
:omap  :onoremap :ounmap       Operator-pending
:map!  :noremap! :unmap!          Insert and Command-line
:imap  :inoremap :iunmap           Insert
:lmap  :lnoremap :lunmap           Insert, Command-line, Lang-Arg
:cmap  :cnoremap :cunmap        Command-line
:tmap  :tnoremap :tunmap           Terminal-Job

 

2. Related references

Key table

<k0> -  <k9> Small keyboard 0 Prior to. 9 
<S-...> the Shift key + 
<C-...> Control + key 
<M-...> Alt + meta + key or keys 
<A-...> with  <M-...> 
<Esc> the Escape key 
<Up> on the cursor key 
<Space> is inserted into a space 
<Tab> inserted Tab 
<CR> is equal to<Enter>

Special parameters

Some special parameters must be mapped after the command and before any other parameters.

<buffer>

<buffer>If the first parameter of these mapping commands is yes <buffer>, the mapping will be limited to the current buffer (that is, the file you are editing at this time). For example: 
:map <buffer> ,w /a<CR> 
it means to define the key binding in the current buffer, ",w" will search the character a in the current buffer. You can also define it in other buffers: For 
:map <buffer> ,w /b<CR> 
example, I often open multiple tabs (:tabedit), and want to define the ",w" key binding in each tab, then you just need to define it separately in each tab. , And its scope is only in the respective tags. To clear the key bindings of these buffers, add <buffer>parameters, such as: 
:unmap <buffer> ,w 
:mapclear <buffer>

<silent>

<silent>It means that
:map <silent> ,w /abcd<CR> 
it will not be displayed on the command line when the key binding is executed. For example, when  you input, w and search for abcd, /abcd will not be displayed on the command line. If there is no <silent>parameter, it will be displayed.

<special>

<special>Generally used to define special keys where side effects are feared. such as: 
:map <special> <F12> /Header<CR>

<expr>

<expr>. If the first parameter to define a new mapping is <expr>, then the parameter will be calculated as an expression, and the result will be actually used. For example: 
:inoremap <expr> . InsertDot() 
This can be used to check the text before the cursor and start the omni complement under certain conditions. all. 
one example:

let counter = 0 
inoremap <expr> <C-L> ListItem() 
inoremap <expr> <C-R> ListReset() 

func ListItem() 
let g:counter += 1 
return g:counter . '. ' 
endfunc 

func ListReset() 
let g:counter = 0 
return '' 
endfunc 

In insert mode, CTRL-L inserts the list number in the order and returns; CTRL-R resets the list number to 0 and returns to empty.

<unique>

<unique>Generally used to define a new key mapping or abbreviation command and check whether the key has been mapped. If the mapping or abbreviation already exists, the command will fail

There are many more specific mapping related content can be found at: help map

Guess you like

Origin blog.csdn.net/lianshaohua/article/details/108388945