2

I'm using gvim. Using vimgrep on current directory to find text across *.sql files. As it searches files, it just shows me file name at a time and in the end opens one file up.

Is it possible to open all files as tabs? Basically I want to open all files because I want to replace the 'vimgrepped' pattern with a some other text.

Omnipresent
  • 29,434
  • 47
  • 142
  • 186

2 Answers2

1

found this plugin pretty helpful in this regard.

http://www.vim.org/scripts/script.php?script_id=1813

Omnipresent
  • 29,434
  • 47
  • 142
  • 186
1

To automate actions on the QuickFix list locations, I have written a command similar to :bufdo or :windo that executes a command for each item.

command! -nargs=+ Qfixdo call QuickFixDo(<q-args>)
function! QuickFixDo(cmd)
    let bufnam = {}
    for q in getqflist()
        let bufnam[q.bufnr] = bufname(q.bufnr)
    endfor  
    for n in keys(bufnam)
        exe 'buffer' n
        exe a:cmd
        update
    endfor
endfunction

Using the function one can open all files mentioned in the QuickFix list by the following command.

:Qfixdo tab sp

In addition, it is possible to repeat the substitution itself the same way.

:Qfixdo %s/pattern/string/
ib.
  • 27,830
  • 11
  • 80
  • 100
  • I like this solution, but please [give credit where due](http://stackoverflow.com/questions/4792561/how-to-do-search-replace-with-ack-in-vim/4793316#4793316). – nelstrom Aug 01 '11 at 14:39
  • @nelstrom: Wow! It is interesting to see how thinking the Vim way could produce almost identical solutions to similar problems. Nevertheless, I came up with this function myself, so the credit for this particular answer is not due to Al, even though the code is indeed very similar. – ib. Aug 02 '11 at 02:59
  • @ib my apologies. It seems daft that Vim doesn't have some kind of *quickfixdo* built in, considering that it has `bufdo`, `windo`, `tabdo` and `argdo`. – nelstrom Aug 04 '11 at 17:24
  • @nelstrom: Don't mention it. Totally agree about the absence of a built-in command for repeating a command on the QuickFix list files. In fact, that is exactly the reason why Vim users would reinvent it over and over. – ib. Aug 05 '11 at 03:09
  • @nelstrom: By the way, searching similar solutions on Stack Overflow (after reading your comment), I found [your idea](http://stackoverflow.com/questions/5686206/search-replace-using-quickfix-list-in-vim/5686810#5686810) of setting `args` to the QuickFix list files and using `argdo`. That's a very elegant workaround! – ib. Aug 05 '11 at 03:16