Vim keyboard mapping (MAP) ~ Reprint

Source: Internet
Author: User
Tags imap

Vim keyboard mapping (map) Setting keyboard mapping

Using the: Map command, you can bind a key on the keyboard to the VIM command. For example, using the following command, you can enclose the word in curly braces with the F5 key:

: Map <F5> i{e<esc>a}<esc>

Where: i{will insert the character {, then use ESC to return to the command state, then use E to move to the end of the word, a} to increment the character}, and then back to the command state. After executing the above command, the cursor is positioned on a word (for example, amount) and the F5 key is pressed, and the character becomes the form of {amount}.

Keyboard mapping in different modes

You can set the keyboard mapping for a specific pattern using the different forms of the map command in the following table:

Command
Command
Normal
General mode
Visual
Visualization mode
Operator Pending
Operator mode
Insert only
Insert mode
Command Line
Command-line mode
:map Y Y Y
:nmap Y
:vmap Y
:omap Y
:map! Y Y
:imap Y
:cmap Y
Keyboard mapping Instance

Use the TAB key and the Shift-tab key to indent text under normal mode and Visual/select mode using the following command:

Nmap <tab> v>nmap <s-tab> v<vmap <tab> >gvvmap <s-tab> <GV

Use the following command to specify the F10 key to create a new tab page:

: Map <F10> <Esc>:tabnew<CR>

Where:<esc> represents the Escape key;<cr> represents the Enter key, while the function key is represented by <F10>. First go to command line mode, then execute the new tab: Tabnew command, and return to normal mode.

Similarly: For key combinations, you can use <C-Esc> to represent ctrl-esc; use <S-F1> to represent SHIFT-F1. For Mac users, you can use <D> to represent the command key.

Note: The ALT key can be represented by using <M-key> or <A-key>.

For a detailed description of the keyboard symbols, use the: H key-notation command to view help information.

We can also set the keyboard mapping for the function. For example, if you add the following code to a. vimrc file, you can use the shortcut keys to turn highlighting on or off for search results.

View Keyboard Mappings

Use the: Map command to list all keyboard mappings. The first column identifies the mode in which the mapping works:

Marker mode <space> general mode, visual mode, operator mode n Normal mode v visual mode o operator mode! Insert mode, command line mode i insert mode C command mode

With the: map! command, only the mappings for insert and command-line modes are listed. Instead: the IMAP,:VMAP,:OMAP,:NMAP command simply lists the mappings in the corresponding mode.

Cancel Keyboard mapping

If you want to cancel a mapping, you can use the following command:

: Unmap <F10>

Note: You must specify a parameter for the: Unmap command. If no parameters are specified, the system will error without canceling all keyboard mappings.

For keyboard mappings in different modes, you need to use the corresponding Unmap command. For example: Use the: Iunmap command to cancel the keyboard mapping in insert mode, and to cancel the keyboard mapping in normal mode, you need to use the: Nunmap command.

If you want to cancel all mappings, you can use the: Mapclear command. Please note that this command will remove all user-defined and system-default keyboard mappings.

Reference
    • Http://yyq123.blogspot.com/2010/12/vim-map.html
    • Vim Key Mapping
Using the SET command
Set pastetoggle=<f9>
Using IMAP commands

Exiting the insertion mode with ESC is cumbersome, and you can map additional keys to this key, as below, mapping Ctrl-i to ESC

IMAP <C-I> <Esc>

= = the end = =

Vim keyboard mapping (MAP) ~ Reprint

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.