开发者

Editing multiple files simultaneously with Vim

I need to add several lines all at the same location to multiple files. I was wondering if I could possibly open all files with Vim, and only make the changes in one file for which the changes will be made in all files simultaneously. I really want to avoid opening X numbe开发者_高级运维r of files, copying this, pasting, then repeating for each file of X files...There's gotta be a better way to do this, hopefully with vim...

Thanks! Amit


You could record macro and execute it on other files. See http://www.thegeekstuff.com/2009/01/vi-and-vim-macro-tutorial-how-to-record-and-play/ for detailed tutorial.


You can use the windo command to operate in all windows. Combine this with a substitute command and you have this (say you want to add "This is a new line." at line 2 in every file):

:windo 2s/\(.*\)/This is a new line.^M\1

Off course, as others noted, there are much better tools for this job (awk comes to mind).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜