Search & replace using quickfix list in Vim?

Vim has bufdo windo tabdo and argdo which let you perform the same command in all open buffers, windows or files in the argument list. What we really need is something like quickfixdo which would invoke a command on every file in the quickfix list. Sadly, that functionality is lacking from Vim, but here's a solution by Al that provides a home-rolled solution.

Using this, it would be possible to run.

Vim has bufdo, windo, tabdo and argdo, which let you perform the same command in all open buffers, windows or files in the argument list. What we really need is something like quickfixdo, which would invoke a command on every file in the quickfix list. Sadly, that functionality is lacking from Vim, but here's a solution by Al that provides a home-rolled solution.

Using this, it would be possible to run: :QFDo %s/foo/bar/gc And that would run the foo/bar substitution on all files in the quickfix list. The bufdo, windo, tabdo and argdo commands have some common behaviour. For example, if the current file can't be abandoned, then all of these commands will fail.

I'm not sure if the QFDo command referenced above follows the same conventions. I've adapted Al's solution to create a command called Qargs. Running this command populates the argument list with all of the files listed in the quickfix list: command!

-nargs=0 -bar Qargs execute 'args ' . QuickfixFilenames() function! QuickfixFilenames() " Building a hash ensures we get each buffer only once let buffer_numbers = {} for quickfix_item in getqflist() let buffer_numbersquickfix_item'bufnr' = bufname(quickfix_item'bufnr') endfor return join(values(buffer_numbers)) endfunction Using this, you could follow these steps to do a project-wide search and replace: :Ggrep findme :Qargs :argdo %s/findme/replacement/gc :argdo update Edit: (with a hat tip to Peter Rincker) Or you could join the last 3 commands together in a single line: :Ggrep findme :Qargs | argdo %s/findme/replacement/gc | update.

I believe you should be using -nargs=0 and -bar in your Qargs command. – Peter Rincker Apr 16 at 15:41 @PeterRincker thanks for pointing that out. I've updated the command.

– nelstrom Apr 16 at 18:25 It's an elegant idea to use args and argdo! I think it could be even better (and more convenient) to join Qargs and argdo commands in one: command! -nargs=1 -complete=command -bang Qargdo exe 'args '.

QuickfixFilenames() | argdo – ib. Aug 5 at 3:31.

External grep (uses grepprg, grepformat like in makeprg/errorformat; if grepprg=='internal' this is identical to internal grep) :grep fopen *. C :copen :cnext Internal grep :vimgrep /\/ **/*. C :copen :cnext etc.Location list internal grep :lvimgrep /\/ **/*.

C :lopen :lnext etc. Bonus: doing external grep for the loaded buffers: :silent bufdo grepadd fstream % :copen :cnext etc.External for all arguments: :silent argdo grepadd fstream % :copen :cnext.

Not sure what you are trying to point out with those examples. I know how to use grep and vimgrep. I don't see how this answer fits the question.

– Zardoz Apr 16 at 22:31 (a) Showing you a few ways to reduce the scope of grep in vim (b) showing you how to do such things for external grep. I'm sorry if it is a bit boring, but it works for me :) – sehe Apr 16 at 22:33.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions