Vim custom commands and shortcut keys

Source: Internet
Author: User
There are five mappings-for normal mode: When you enter a command. -For visual mode: When the visible area is highlighted and a command is entered. -For operator waiting mode: the operator is waiting (& quot; d & quot;, & quot; y & quot;, & quot; c & quot ). See: | omap-info |. -For insert mode: also...

Five mappings exist.
-For normal mode: When you enter a command.
-For visual mode: When the visible area is highlighted and a command is entered.
-Used for operator waiting mode: the operator is waiting ("d", "y", "c", etc ).
See: | omap-info |.
-For insert mode: It is also for replace mode.
? For command line mode: Enter the ":" or "/" command.

The following table shows the mode code of map binding. Now let's take a look at it. after reading it, we will see the pattern code.
Font mode ~
Common, visualized, selection, and operator waiting
N normal
V visualization and selection
S selection
X visualization
O operator waiting
! Insert and command line
I insert
L ": lmap" ing of insert, command line, and Lang-Arg mode
C command line


I will mainly explain the two binding commands under "n (normal mode)". after reading the commands, I will understand the commands in other modes.
The ing commands for common modes mainly include:
1.: map
[Syntax]: map {lhs} {rhs} | mapmode-nvo | *: map *
1.1 mode of action: n, v, o (common, visual, and selection, operator waiting)
1.2 command format:
: Map {lhs} {rhs}
Meaning: in the map mode, the key series {lhs} is mapped to {rhs}, and {rhs} can be mapped for scanning, that is, recursive ING.
1.3 Example:
: Map td: tabnew.
Meaning: in its effective mode (normal, visualized, and operator), the input td is equivalent to the input tabnew. . In normal mode, the input is tabnew. Is to open the current directory
If you re-define the binding: map ts td, it means that in the effective mode, the input ts is equivalent to td, that is, to open the current directory. However, if there is no special need, recursive ING is generally not recommended.

2.: noremap
: Compared with the: map command, the mode and command format are the same, but the {rhs} ing scan is not allowed, that is, the ing defined by {lhs} is the key sequence of {rhs} and will not re-interpret and scan the {rhs} key sequence. It is generally used to redefine a command. if: map does not require recursive ING, we recommend that you use: noremap
For example:
: Noremap ts td
In this mode, the input ts is the input td, but unlike map, the td will not be further scanned. Although td has been defined before, but does not scan td again

3.: unmap
: Unmap is the {lhs} bound to the unmap. it works in the same mode. command format: unmap {lhs }.
For example:
: Unmap td
Cancel the binding of td in the action mode. for example, if td was previously bound to: tabnew. In this case, the binding disappears.
4.: mapclear
: When mapclear is used, cancel all: map bound. use it with caution!

5.: nmap
: Nmap is the normal mode board of map. that is to say, the bound key only applies to the normal mode.
For example:
: Nmap td: tabnew. And: map td: tabnew. Equivalent in normal mode
6.: nnoremap
: The relationship between nnorempa and: nmap is the same as that between: noremap and: map, except that nmap is non-recursive.
7.: nunmap
The relationship between: nunmap and: nmap is the same as that between: unmap and: map. cancel: nmap binding.
8.: nmapclear
: Nmapclear cancels all: map binding. use it with caution!

After reading the above, we can find a rule. the first four are a group, the last four are a group, and the last one is n more than the previous one, that is, it only applies to the normal mode. * Nore * in each group is its non-recursive version, and * un * is to unbind a certain Binding and clear suffixes cancel all bindings. After finding this rule, go to the previous schema code table. you can roughly guess what vmap, xmap, smap, and omap mean, and the corresponding nore version, un version, and clear version.

In addition:
A special character may be displayed before {rhs:
* Indicates that it cannot be remapped.
& Indicates that only local mappings of scripts can be remapped.
@ Indicates the local ING of the buffer.

At this point, you can take a long breath, because the relevant commands have been understood, and it does not matter, you can at any time: help map. But don't worry. there are more options to map in the future.

Key table | key-notation |
- Keypad 0 to 9 * keypad-0 ** keypad-9 *
Shift + Key * shift **
Control + Key * control ** ctrl **
Alt + key or meta + Key * meta ** alt **
Same * "Xx" entry key in termcap

Special parameters:
1.
2.
3.
4. script
5.
6.
They must be mapped to the back of the command, before any other parameter.

If the first parameter of these ing commands is , ING will only be confined to the current buffer (that is, the file you are editing at this time. For example:
: Map , W/
It defines key binding in the current buffer, and ", w" searches for character a in the current buffer. You can also define in other buffers:
: Map , W/B
For example, if I often open multiple tags (tabedit) and want to define the ", w" key binding in each tag, you only need to define them in each tab, its scope is only in the respective labels. The key binding to clear these buffers also needs to be added Parameters, such:
: Unmap , W
: Mapclear

It means that the key binding is not performed on the command line Echo, for example:
: Map , W/abcd
When you enter w to search for abcd, the command line will not display/abcd. If no The parameters are displayed.

It is generally used to define special keys to avoid side effects. For example:
: Map /Header

It is generally used to define a new key ing or abbreviated command and check whether the key has been mapped. if the ing or abbreviated command already exists, the command will fail.

. If the first parameter for defining the new ING is , Then the parameter is calculated as an expression, and the result is actually used For example:
: Inoremap . InsertDot ()
This can be used to check the text before the cursor and enable omni completion under certain conditions.
Example:
Let counter = 0
Inoremap ListItem ()
Inoremap ListReset ()

Func ListItem ()
Let g: counter + = 1
Return g: counter .'.'
Endfunc

Func ListReset ()
Let g: counter = 0
Return''
Endfunc
In insert mode, the CTRL-L inserts the list number of the order and returns; the CTRL-R resets the list number to 0 and returns null.


Mapleader
The mapleader variable is effective for all map commands. Replace it with the value of the mapleader variable, for example:
: Map A oanother line
If the mapleader variable is not set, use the default backslash instead. Therefore, this ING is equivalent:
: Map \ A oanother line
When the \ A key is input, the next line enters another line and returns to normal mode.
If the mapleader variable is set, for example:
Let mapleader = ","
This is equivalent:
: Map, A oanother line

Maplocalleader
And Similarly, it only acts on the buffer zone.
Therefore, it is best to separate mapleader and maplocalleader without conflict.

 

Author "venus585625"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.