开发者

How to add a piece of code in the same pace in all the files within a folder in Vim?

开发者 https://www.devze.com 2022-12-27 00:27 出处:网络
I want to add this code: <link rel=\"stylesheet\" type=\"text/css\" href=\"css/global.css\" /> <!--[if lt IE 8]>

I want to add this code:

<link rel="stylesheet" type="text/css" href="css/global.css" />
<!--[if lt IE 8]>
    <link rel="stylesheet" type="text/css" href="css/iehacks.css" />
<![endif]-->

to all the files开发者_运维问答 in a folder right before the </head> tag


I'm not sure if this is possible with vim, but you can always execute a shell command from it. Both sed and perl can do inplace file edits. Have a look here and here.


I would record a macro to insert the text, then do a :bufdo to apply it to all open files.

Example:
Open all files in vim, then record a macro in register x with qx, go to the top of the file with gg, search for the end of the head-tag with /\/head, open a line before that with O (big O), then type or paste your text as usual, write your file with :w, end the recording with q.

After that, run :bufdo normal @x to apply it to all open buffers.

0

精彩评论

暂无评论...
验证码 换一张
取 消