Running a Vim macro on a set of lines with norm

21 篇文章 4 订阅

提供了我们全文选择,然后再在选中的行运行宏的办法, normal 是个很有用的东西,其意义就是在command中运行一些norm model下的操作, 提供了我们很多组合操作的可能,拓展了使用vim的维度, 比如

:g/\/\// norm dd可以删除所有的注释代码行。

It’s occasionally handy to be able to run a macro that you’ve got ready on aspecific subset of lines of the file, or perhaps just for every line.Fortunately, there’s a way to do this, too.

Using the :normal command, you’re able to run macros from the ex command line:

:normal @a

All it takes is prefixing this with any sort of range definition to allowyou to run a macro on any set of lines that you’re able to define.

Run the macro on each line of the whole buffer:

:% normal @a

Between lines 10 and 20:

:10,20 normal @a

On the lines in the current visual selection:

:'<,'> normal @a

On the lines containing the pattern vim:

:g/vim/ normal @a

When you get confident using this, :norm is a nice abbreviation to use.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值