Best find and replace in files practices
Folks, sorry if this topic was already discussed for too many times but i couldn't google anything useful :( Grepping for something seems to be trivial with :vimgrep and :grep but there's nothing simple like this for 'searchreplace' and i wonder why... Is it done intentionally or i'm just missing something? Probably experienced vim users(i'm not amongst them) prefer using shell one-liners(say, perl or sed) for such tasks instead of trying this in vim? But maybe i'm completely wrong and it's possible with vim as well? (oh, i'm dreaming to have this in vim and preview replaced results in a quickfix window...) Could you guys please share your tips for this sort of functionality? Thanks in advance. -- Best regards, Pavel
Re: Best find and replace in files practices
On 2/25/07, Tim Chase [EMAIL PROTECTED] wrote: Grepping for something seems to be trivial with :vimgrep and :grep but there's nothing simple like this for 'searchreplace' and i wonder why... Is it done intentionally or i'm just missing something? Just missing the power of the argdo/windo/bufdo commands: Thank you very much, i'm surely going to have a deep look at these commands. BTW, is it possible(i don't have vim installed on this box) to find something with :vimgrep and then use :argdo to replace? I'm asking about this because IMHO opening ~500 files with vim *.txt just to replace something in several files looks like an overkill, no? -- Best regards, Pavel
Re: Best find and replace in files practices
On 2/25/07, Pavel Shevaev [EMAIL PROTECTED] wrote: On 2/25/07, Tim Chase [EMAIL PROTECTED] wrote: Grepping for something seems to be trivial with :vimgrep and :grep but there's nothing simple like this for 'searchreplace' and i wonder why... Is it done intentionally or i'm just missing something? Just missing the power of the argdo/windo/bufdo commands: Thank you very much, i'm surely going to have a deep look at these commands. BTW, is it possible(i don't have vim installed on this box) to find something with :vimgrep and then use :argdo to replace? I'm asking about this because IMHO opening ~500 files with vim *.txt just to replace something in several files looks like an overkill, no? When vim is given 500 file arguments, it opens only the first one. Regarding the other 499 files, it just remembers the names, for the beginning, so you see the first tfile very quicky. Only when you explicitly visit/open some of the other files, vim will actually read its contents. Just try it out. It works fast. Yakov
Re: Best find and replace in files practices
When vim is given 500 file arguments, it opens only the first one. Regarding the other 499 files, it just remembers the names, for the beginning, so you see the first tfile very quicky. Only when you explicitly visit/open some of the other files, vim will actually read its contents. Just try it out. It works fast. That sounds great but how to deal with dreadful too many arguments bash error? Using something like $ find -type f -name '*.txt' | xargs vim --remote? Yakov -- Best regards, Pavel
Re: Best find and replace in files practices
On 2/25/07, Pavel Shevaev [EMAIL PROTECTED] wrote: When vim is given 500 file arguments, it opens only the first one. Regarding the other 499 files, it just remembers the names, for the beginning, so you see the first tfile very quicky. Only when you explicitly visit/open some of the other files, vim will actually read its contents. Just try it out. It works fast. That sounds great but how to deal with dreadful too many arguments bash error? Using something like $ find -type f -name '*.txt' | xargs vim --remote? Maybe this will work: vim :args ** or :args * */** ? Yakov
Re: Best find and replace in files practices
Pavel Shevaev wrote: On 2/25/07, Tim Chase [EMAIL PROTECTED] wrote: Grepping for something seems to be trivial with :vimgrep and :grep but there's nothing simple like this for 'searchreplace' and i wonder why... Is it done intentionally or i'm just missing something? Just missing the power of the argdo/windo/bufdo commands: Thank you very much, i'm surely going to have a deep look at these commands. BTW, is it possible(i don't have vim installed on this box) to find something with :vimgrep and then use :argdo to replace? I'm asking about this because IMHO opening ~500 files with vim *.txt just to replace something in several files looks like an overkill, no? You still have to open them in :vimgrep (:verbose shows that :vimgrep reads the viminfo for every file scanned so I guess it opens the files as for editing). What you can avoid is the rewrite of unchanged files, by using :update rather than :w after the substitute: :args *.txt :argdo %s/\John\/Jack/g |up Best regards, Tony. -- Texas law forbids anyone to have a pair of pliers in his possession.