Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use Vimscript

Shulou Source: shulou.com Published: 2022-05-31 19:28:40 10月03日 Update

This article is to share with you about how to use Vimscript. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

If there is one feature of Vimscript that allows you to customize Vim according to your wishes, it is keyboard mapping. You can tell Vim through keyboard mapping:

When I press this button, I need you to give up the default action and do what I want.

Let's start with the keyboard mapping in normal mode. We will discuss keyboard mapping in insert mode and other modes in the next section.

Type a few lines in the text at will, and then run the command:

: map-x

Place the cursor somewhere in the text and press -. Notice that Vim deletes the characters under the current cursor as if you had pressed x.

We already have a button to "delete characters under the current cursor", so we remap-to something slightly useful. Execute the command:

: map-dd

Now move the cursor to any line and press-- this time Vim deletes the entire line of text, because the function of dd is to delete the entire line.

Special character

You can use a special button to tell Vim. Try the following command:

: map viw

Move the cursor over a word and press the spacebar. Vim highlights the entire word.

You can also map modifiers by typing Ctrl and Alt. Execute:

: map dd

Pressing Ctrl+d on the keyboard now executes the dd command.

Annotation

Remember the notes we discussed in the first chapter? Comments cannot be used for keyboard mapping. Try the following command:

: map viw "Select word

Now you press the spacebar again, and something terrible will happen. Think about why this is happening.

When you press the spacebar, Vim thinks you are trying to execute the command viw "Selectword. Obviously, this is not your intention.

If you take a closer look at the results of this mapping, you may find something strange. Take a few minutes to figure out what happened when using this mapping and why it turned out that way.

Thank you for reading! This is the end of the article on "how to use Vimscript". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Commands keyboards cursors characters text patterns comments spaces space keys special content functions words keys more articles results try move good Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Microsoft Shulou Information Shulou Technology vpn