Input :
<Action name="Compile" />
<Action name="Debug" />
Ouput:
<Action name="Parse" />
<Action name="Compile" />
<Action name="Debug" />
使用vim
,我如何搜索行开始包含单词“编译”,并预先在另一行的行?vim,如何搜索文本,并在搜索行之前添加新行
我累:%s
但它不是更换整个线
Input :
<Action name="Compile" />
<Action name="Debug" />
Ouput:
<Action name="Parse" />
<Action name="Compile" />
<Action name="Debug" />
使用vim
,我如何搜索行开始包含单词“编译”,并预先在另一行的行?vim,如何搜索文本,并在搜索行之前添加新行
我累:%s
但它不是更换整个线
我会做王子土豆烧牛肉的方式,但...
:%s/^.*Compile/<Action name="Parse" \/>\r&
^.*Compile " matches everything from the first char on the line
" up to and including 'Compile'
<Action name="Parse" \/>\r& " replaces the match with the new desired line,
" followed by a newline, followed by the match
或非常优雅...
:g/Compile/t-|s//Parse
:g/Compile/t- " copies the matching line above itself
:s//Parse " substitutes the last search pattern with 'Parse'
" on that new line
可以使用:g
命令搜索线,然后对每个匹配的行提供一个:normal!
命令:
:g/Compile/normal! O<Action name="Parse" />
的!
确保在调用:normal
时不会调用用户映射。
工作就像一个魅力 – 2014-11-03 08:29:27
有:%s和/ GC现在我可以有选择地更换物品 – 2014-11-03 08:53:28