how to open multiple files in vim after vimgrep

1.2k Views Asked by At

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.

2

There are 2 best solutions below

5
On BEST ANSWER

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/
0
On

found this plugin pretty helpful in this regard.

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