Get the App
SLTechnology News&Howtos  ›  Servers  › 

Introduction of Mapping function in vim Editor

Shulou Source: shulou.com Published: 2022-06-03 03:36:32 09月22日 Update

What is mapping?

Mapping can be understood as setting shortcut keys, which allows you to replace more and more keys with a small number of keys that are easy to press.

When to use mapping

If you have one or more of the following troubles, you can use mapping.

Dissatisfied with the current button

Want to set some keyboard shortcuts to improve editing speed

Want to combine some buttons to complete the new requirements

Classification of mappings

We know that vim has a variety of modes, and corresponding mappings include nmap (normal mapping), imap (insert mapping), and vmap (block selection mapping).

Let's select several cases to talk about these three mappings.

General mapping

"use F1 to toggle display line number nmap: set nu! nu?

The CR here means enter.

Insert Mapping

"use jj instead of the ESC key to return from insert mode to normal mode imap jj `^

We usually use jj instead of the ESC key to quickly switch from insert mode to normal mode.

"delete the character imap imap lxi forward and backward in insert mode

Where c represents the ctrl key, in insert mode, use ctrl+b to delete one character backward, and ctrl+d to delete one character forward.

Block pattern mapping

In general, we often increase or decrease the indentation of multi-line text. As mentioned in the previous article, this requirement can be achieved through block selection combined with the command line, or through macros. Today, after learning about mapping, you can use a simpler method to implement the requirements.

Vmap

< >

Gv

Now, if we want to indent multiple lines, just select them and press > or

Tags: Recursion mode normal character demand selection that is shortcut keys keys multiline toggle work loop content just you can pass commands enter keys multiple multiple Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Docker Shulou Tech Info Apple Redmi