1

I'm looking for a way to write content of a quickfix window to a file with a specific formatting, preferably in a way that is easily scriptable.

What I'm trying to achieve is a very light integration of Vim and ipdb:

  1. I set 'breakpoints' as items on a quickfix list with mapping: nmap <leader>s :call setqflist([], 'a', {'items': [{'filename': @%, 'lnum':line('.'), 'text':'break'}]})
  2. Write content of the quickfix to .pdbrc file with break file_path:line_number formatting
  3. Run ipdb on specified script
Christoph John
  • 3,003
  • 2
  • 13
  • 23
  • 1
    I just checked, you can definitely save quickfix contents using `:w`. – wxz May 04 '21 at 01:16
  • yeah, i know, but what if quickfix window is not currently open? and this misses my formatting requirement – Wojciech Książek May 04 '21 at 06:09
  • Presumably, you're going to write a vim function that does all this automatically. So in that function, after you get the formatting done, you can do a quick set of calls (`:copen`, `:w save_file`, and `:q`) to open quickfix, save to file, and close it. That takes care of one problem. The other is the formatting which hopefully romainl's answer helps you solve. – wxz May 04 '21 at 13:23

1 Answers1

6

You have two problems:

  1. Turning items into a list of properly formatted lines.

    You will need to:

    • get the quickfix list with :help getqflist(),
    • format each item of the list with :help map(),
    • derive file_path from the bufnr field with :help bufname() and possibly :help fnamemodify().
  2. Writing that list to a given file.

    You will need :help writefile().

romainl
  • 186,200
  • 21
  • 280
  • 313