Thursday 15 July 2010

vim, how to search text and prepend new line before searched line -



vim, how to search text and prepend new line before searched line -

input : <action name="compile" /> <action name="debug" /> ouput: <action name="parse" /> <action name="compile" /> <action name="debug" />

using vim, how can search line starts contains word "compile" , prepend line line ?

i tired :%s not replacing entire line

i prince goulash's way but…

:%s/^.*compile/<action name="parse" \/>\r& ^.*compile " matches first char on line " , including 'compile' <action name="parse" \/>\r& " replaces match new desired line, " followed newline, followed match

or very elegant…

:g/compile/t-|s//parse :g/compile/t- " copies matching line above :s//parse " substitutes lastly search pattern 'parse' " on new line

vim

No comments:

Post a Comment