How to use vim recording

When using vim, I accidentally touched the q key, and the "recording" logo appeared in the lower left corner. I was curious, so I checked it online, and this is a powerful function of vim. He can record a macro (Macro), after starting to record, it will record all your keyboard input, including input in insert mode, various commands used in normal mode, etc.

Specific use:

Step 1: Press the q keyboard in normal mode (non-insert mode, non-visual mode)

Step 2: Select az or any one of 0-9 as the name of the buffer, ready to start recording macros

Step 3: Normal operation, this time all operations will be recorded in the buffer defined in the previous step

Step 4: Enter q to stop macro recording in non-insert mode

Step 5: Use @ + the name of the buffer defined in the second step.

For example, want to put the following text

becomes the following text

Observation can find their regularity, add "System.out.println(" at the beginning of each line of text, and add ");" at the end to become the following information. The following is a brief introduction to how to use recording to complete such an operation.
First move the cursor on line1, enter qt, ready to start recording, the name of the buffer is t, the recording action is: shift + ^ to return to the beginning of the line, press the i key to enter the insert mode, enter "System.out.println( ", press the esc key to return to the normal mode, shift + $ to return to the end of the line, press the i key to enter the insert mode, enter ");" Press the esc key to return to the normal mode, and press the q key to stop recording. Then move the cursor to any position on the following line and enter @ + t.

Recording can also be used in conjunction with queries. For example, if you want to comment a line containing a specific string in a file, you can use such a macro. Type /search string + enter, shift + ^, i, #, esc, shift + $ in normal mode.

The way to have a custom macro run multiple times automatically is to enter a number followed by @ + the name of the buffer. For example, 100@t means 100 executions.

本文转自:http://www.netingcn.com/vim-recording-function.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325992580&siteId=291194637