"Vim" uses map to customize shortcut keys

Source: Internet
Author: User

About Map

Map is a map command that maps frequently used long commands to a new function key. Map is a powerful reason for vim, you can customize a variety of shortcut keys, used naturally handy.

Types of mappings

There are five kinds of mappings present:

  • For normal mode: When the command is entered.
  • For visual mode: when the visible area is highlighted and the command is entered.
  • For operator wait mode: operator wait (after "D", "Y", "C", etc.).
  • For insert mode: Also used for substitution mode.
  • For command line mode: When the ":" or "/" command is entered.

Introduction to several modes
    1. Normal Mode
      That is, the general Normal mode, the default into Vim, in this mode.

    2. Visual Mode
      General translation visual mode, in which some characters, rows, and multiple columns are selected.
      In normal mode, you can press V to enter.

    3. Insert Mode
      Insert mode, in fact, refers to the state of editing input. In normal mode, you can press I to enter.

    4. Select Mode
      Select the mode. When you drag the area with the mouse, you enter the selection mode. And the visual mode is different, in this mode, after the selection of the highlighted area, tap any button to directly enter and replace the selected text. The same effect as the editor selected under Windows. In normal mode, you can enter by GH.

    5. Command-line/ex Mode
      command-line mode and ex mode. The two are slightly different, normal mode by the colon (:) into command-line mode, you can enter a variety of commands,
      Use the various powerful features of VIM. In normal mode, pressing Q into the EX mode is actually a multi-line command-line mode.

Combination of commands

Like other commands under Vim, the name of the command is often made up of several paragraphs. The prefix is used as the modifier of the command itself to fine-tune the effect of the command.
For map, there are several possible prefixes:

*nore
Represents a non-recursive.
A recursive mapping. In fact, it is very well understood, that is, if the key A is mapped into a b,c and mapped to a, if the map is recursive, then C is mapped to B.
* N
Indicates effective in normal mode
* V
Indicates effective in visual mode
* I
Indicates effective in insert mode
* C
Indicates effective in command-line mode

Map commands for Normal mode map

command format:
:map {lhs} {rhs}
The implication is that in the mode of map action, the mapping of the key series {LHS} to {RHS},{RHS} can be mapped, that is, recursive mapping.

Example:
:map td :tabnew .<cr>
Meaning: In its mode of action (normal, visible, operator), input TD equivalent to input: tabnew. 。 In normal mode, enter: Tabnew. is to open the current directory
If the binding is defined again: Map TS TD means that the input TS is equivalent to TD in its mode of action, that is, open the current directory. However, recursive mapping is generally not recommended if there is no special need.

Noremap

: Noremap and: The map command is relative, the action mode and the command format are the same, except that the mapping of {RHS} is not allowed to scan, that is {LHS} after the definition of the map is {RHS} key sequence, no longer the {RHS} key sequence to re-interpret the scan. It is generally used to redefine a command, and of course if: Map does not require recursive mapping, it is recommended to use: Noremap
Like what:
:noremap ts td
It means that in its mode of action, input TS is input TD, but and: map is different, at this time TD will not do further scanning interpretation. Although TD has been defined before, it does not scan the TD again.

Unmap

: Unmap is the corresponding cancel: map bound {LHS}, with the same mode of action, command format: unmap {LHS}.
For example:
:unmap td
is to cancel the binding of TD in its mode of action, for example, before TD is bound to: tabnew., this binding disappears at this time.

Mapclear

: Mapclear when the corresponding cancellation of all: Map binding, use with caution!

For normal mode only.

: Nmap
: Nmap is: Map's normal mode board, that is, its bound keys are only used in normal mode.
For example:
: Nmap td:tabnew. And: Map td:tabnew. Equivalent in normal mode
: Nnoremap
: Nnorempa and: Nmap relations and: Noremap and: Map of the same relationship, just: nmap non-recursive version
: Nunmap
: Nunmap and: Nmap's relationship with: Unmap and: Map of the same relationship, Cancel: Nmap binding.
: Nmapclear
: Nmapclear is the corresponding cancellation of all: Map binding, use with caution!

Other than that

A special character may be displayed before {RHS}:
* Indicates that it is not remap
& indicates that script-only local mappings can be remapped
@ Represents a local mapping of a buffer

In this step you can easily take a long breath, because the relevant commands have been understood, can not remember it's okay, at any time: Help map a bit.

Key table

-Numpad 0 to 9

Special parameters

Some special parameters must be mapped behind the command, before any other parameters.

If the first parameter of these map commands is, the mapping will be confined to the current buffer (that is, the file you are editing at this time). Like what:
: Map, w/a
It means to define a key binding in the current buffer, ", w" will look for the character a in the current buffer. You can also define in other buffers:
: Map, w/b
For example, I often open multiple tags (: tabedit), and want to define ", W" key bindings in their respective tags, so you can define them separately in each tab, and their scopes are only in their own tags. Also, to clear the key bindings for these buffers is to add parameters, such as:
: Unmap, W
: Mapclear

is when the key binding is not echoed on the command line, such as:
: Map, W/ABCD
When you enter, W finds ABCD,/ABCD is not displayed on the command line and is displayed if no parameters are present.

Typically used to define special keys for the occasion of fear of side effects. Like what:
: Map/header

. If the first parameter defining the new mapping is, then the argument is evaluated 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 to start the omni complement under certain conditions.
An example:

 LetCounter= 0Inoremap<Expr> <C- L>ListItem () Inoremap<Expr> <C- R>Listreset () func ListItem () LetG:counter+= 1 returnG:counter. '. 'Endfunc func Listreset () LetG:counter= 0 return "'Endfunc

In insert mode, CTRL-L inserts the order of the list number and returns the Ctrl-r reset list number to 0, and returns NULL.

It is generally used to define a new key mapping or abbreviation command while checking whether the key is already mapped, and if the mapping or abbreviation already exists, the command fails

and Mapleader variables

The Mapleader variable works for all map map commands, and it is useful to replace the parameter with the value of the Mapleader variable, such as:
: Map A Oanother Line
If the Mapleader variable is not set, it is replaced with the default backslash, so this mapping is equivalent to:
: Map \a Oanother Line
When entering the \a key, enter another line in the next row and return to normal mode.
If a Mapleader variable is set, for example:
Let Mapleader = ","
Then it is equivalent to:
: Map, A Oanother Line

and Maplocalleader variables

and similar, except that it only makes use of buffers.
Therefore, when setting Mapleader and Maplocalleader, it is best to distinguish between regions and avoid conflicts.

reprint Please indicate the author Jason Ding and its provenance
Gitcafe Blog Home page (http://jasonding1354.gitcafe.io/)
GitHub Blog Home page (http://jasonding1354.github.io/)
CSDN Blog (http://blog.csdn.net/jasonding1354)
Jane Book homepage (http://www.jianshu.com/users/2bd9b48f6ea8/latest_articles)
Baidu Search jasonding1354 access to my blog homepage

"Vim" uses map to customize shortcut keys

Related Article

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.