在 Vim 中,如何将宏应用于一组行? [英] In Vim, how do I apply a macro to a set of lines?
问题描述
我有一个包含一堆行的文件.我录制了一个在单行上执行操作的宏.我想在文件中的所有剩余行上重复该宏.有没有快速的方法来做到这一点?
I have a file with a bunch of lines. I have recorded a macro that performs an operation on a single line. I want to repeat that macro on all of the remaining lines in the file. Is there a quick way to do this?
我尝试了 Ctrl+Q,突出显示了一组行,然后按了 @@,但这似乎并没有奏效.
I tried Ctrl+Q, highlighted a set of lines, and pressed @@, but that didn't seem to do the trick.
推荐答案
使用 normal 在 Ex 模式下在多行/所有行上执行宏的命令:
Use the normal command in Ex mode to execute the macro on multiple/all lines:
在第 5 行到第 10 行执行寄存器 a 中存储的宏.
Execute the macro stored in register a on lines 5 through 10.
:5,10norm! @a
在第 5 行到文件末尾执行寄存器 a 中存储的宏.
Execute the macro stored in register a on lines 5 through the end of the file.
:5,$norm! @a
在所有行上执行寄存器 a 中存储的宏.
Execute the macro stored in register a on all lines.
:%norm! @a
在匹配模式的所有行上执行寄存器a中的宏存储.
Execute the macro store in register a on all lines matching pattern.
:g/pattern/norm! @a
要在视觉上选择的行上执行宏,请按 V 和 j 或 k,直到选择了所需的区域.然后输入 :norm!@a
并观察显示以下输入行.
To execute the macro on visually selected lines, press V and the j or k until the desired region is selected. Then type :norm! @a
and observe the that following input line is shown.
:'<,'>norm! @a
在 vim 中输入 :help normal 以阅读更多内容.
Enter :help normal in vim to read more.
这篇关于在 Vim 中,如何将宏应用于一组行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!