Quickfix list, how to add and remove entries

Update: New official vim plugin cfilter

Since 21.8.2018 (patch: 8.1.0311) the plugin cfilter is distributed in $VIMRUNTIME itself. It is documented under :h cfilter-plugin.

Load plugin cfilter when needed or load it always in your vimrc

:packadd cfilter

Filter quickfix list with

:Cfilter DPUST

I found your question while looking particularly for the ability to remove items from the quickfix list. I'm not super good at vimscript, so there's probably a more elegant solution, but here's what I came up with.

This overrides dd in the quickfix list (which is pretty much useless anyway, since modifiable is off) to remove the current line (the current line of the cursor, not the current quickfix item) from the quickfix list.

I couldn't figure out how to programmatically determine the current quickfix item, which is how I settled on using dd, to make it more obvious that it applies to the line of the cursor.

I hope you might find this useful.

" When using `dd` in the quickfix list, remove the item from the quickfix list.
function! RemoveQFItem()
  let curqfidx = line('.') - 1
  let qfall = getqflist()
  call remove(qfall, curqfidx)
  call setqflist(qfall, 'r')
  execute curqfidx + 1 . "cfirst"
  :copen
endfunction
:command! RemoveQFItem :call RemoveQFItem()
" Use map <buffer> to only map dd in the quickfix window. Requires +localmap
autocmd FileType qf map <buffer> dd :RemoveQFItem<cr>

UPDATE: I've fixed a few issues I've found with the above function.

Tags:

Vim