6

I usually find myself running pattern replacements on the results of vim-fugitive's Ggrep

:Ggrep someFunctionName
:cfdo %s/someFunctionName/someOtherName/g | update

And that works great but I can still see someFunctionName on the quickfix matches.

I know the quickfix gets those values from another function and it doesn't keep track of the actual files, but I'm wondering if there's a way to read the locations and refresh them with the new content.

davidmh
  • 193
  • 6

1 Answers1

3

I am sure there is a better way, but this is how I would do it:

call setqflist(map(getqflist(), 'extend(v:val, {"text":get(getbufline(v:val.bufnr, v:val.lnum),0)})'))

Basically use getqflist() to get each Quickfix line. Using getbufline() to get each newly updated line. Then update the quickfix list via setqflist().

Note: This relies on getbufline() which requires the buffer to be loaded to get a line back properly (:cfdo should load the buffers).

For more help see:

:h setqflist()
:h getqflist()
:h map()
:h extend()
:h getbufline()
:h get()
:h :call
Peter Rincker
  • 15,854
  • 1
  • 36
  • 45
  • That's awesome stuff, thank you.

    I don't even need to worry about opening the buffers, cfdo already does that for me.

    I'll use your answer in this custom command: command! UpdateQF call setqflist(map(getqflist(), 'extend(v:val, {"text":get(getbufline(v:val.bufnr, v:val.lnum),0)})'))

    That way I can do: :cfdo %s//something/g | update | UpdateQF

    – davidmh Sep 21 '17 at 20:16
  • 1
    Using UpdateQF inside cfdo %s//something/g | update | UpdateQF is creating a new quickfix list for every file. I imagine this could make quickfix list history useless. May want to do it as a separate command after the executing your :cfdo command. – Peter Rincker Sep 21 '17 at 20:56