On Di, 26 Okt 2010, Asis Hallab wrote:
> I recently discovered and used vim's
> args and argdo commands.
> 
> Now I wonder if there's a way to execute a command over all search-results
> in the quickfix or location-list?
> E.g.
> vimgrep 'define' **/*.rb
> and then on all files in the quickfix, or location list
> *quickfix_do* %s/define/def/g
> 
> Your help is very much appreciated.
This one here works with the quickfixlist / locationlist (the bang 
form):
fun! QFDo(bang, command)
     let qflist={}
     if a:bang
         let tlist=map(getloclist(0), 'get(v:val, ''bufnr'')')
     else
         let tlist=map(getqflist(), 'get(v:val, ''bufnr'')')
     endif
     if empty(tlist)
        echomsg "Empty Quickfixlist. Aborting"
        return
     endif
     for nr in tlist
     let item=fnameescape(bufname(nr))
     if !get(qflist, item,0)
         let qflist[item]=1
     endif
     endfor
     :exe 'argl ' .join(keys(qflist))
     :exe 'argdo ' . a:command
endfunc
com! -nargs=1 -bang Qfdo :call QFDo(<bang>0,<q-args>)
regards,
Christian
-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
 
No comments:
Post a Comment