Macros are a collection of commands and are widely used, including the word editor in MS Office, the Excel editor and various text editors, and Vim, one of the most powerful text editors in Linux systems, also supports macro operations, and this section briefly describes the use of macros in Vim, First look at the following macro commands
- q* Start Recording macros
- Q Stop Recording macro
- @* executing a macro
- @@ 重复 executes the last @* command once
The above commands are used under the general mode of Vim (normal), where * represents a number and a word character, and the regular expression rule is: [0-9a-za-z]
- : Help Recording viewing macros
For example, in the general mode of entering QQ will see the status bar below vim appears recording, this means that you have started recording macro to register Q, you can also use Q as the ID of the macro, the command will be recorded in the macro, again in general mode, press Q to stop the macro recording, You can call the macro via @q later.
To give a simple example, here's a snippet of code:
function(name,value,count){ ...}function(dc,mel){ ...}function(op,ts,n){ ...}
Now you want to modify the declaration format of the function so that a space is added between multiple arguments
1. First QQ to start a macro recording, command mode input: s/,/,\/g
2. Q to end macro recording
3. Move to the next function declaration position @q Execute Macro command
Using Macros macro in VIM