发现 evil 实现的 :g
/ :v
命令好像有性能问题。
比如要将选中区域中的所有匹配 /re1/
的行中的所有的和 /re2/
相匹配的部分替换为 result
。
用 evil 的 :'<,'>g/re1/s/re2/result/g
会非常的慢,即便是只有几百行文本。
这个例子可以用 heml-swoop
替代:
- 使用
narrow-to-region
(Spacemacs:SPC n r
) narrow 当前的选中区域。 - 启动
helm-swoop
(Spacemacs:SPC s s
) - 输入模式
re1
,这样 swoop 就会筛选出所有和 re1 匹配的行;如果是想取反的话(筛选出所有和 re1 不匹配的行),可以输入!re1
C-c C-e
- 在 swoop edit buffer 中使用 evil 的
:s
来进行替换,或者使用 Spacemacs 的 iedit 手工选择性地替换;如果想删除这些匹配到的行可以根据 swoop eidt 的提示使用C-c C-q C-g
删除匹配某个模式的所有行也可以用 delete-matching-lines
,删除不匹配某个模式的所有行也可以使用 delete-non-matching-lines
。