Use a function with range keyword (
:h func-range
) for processing your visual selection. Moreover, that also allows for[count]
in Normal mode.Prefer buffer-local mappings whenever it makes sense.
" using range-aware function function! QFdelete() range " get current qflist let l:qfl = getqflist() " no need for filter() and such; just drop the items in range call remove(l:qfl, a:firstline - 1, a:lastline - 1) " replace items in the current list, do not make a new copy of it; " this also preserves the list title call setqflist([], 'r', {'items': l:qfl}) " restore current line number call cursor(a:firstline, 1) endfunction
" using buffer-local mappings " note: still have to check &bt value to filter out
:e quickfix
and such augroup QFList | au! autocmd BufWinEnter quickfix if &bt ==# 'quickfix' autocmd BufWinEnter quickfix nnoremap dd :call QFdelete() autocmd BufWinEnter quickfix vnoremap d :call QFdelete() autocmd BufWinEnter quickfix endif augroup end
Matt
- 21.6k
- 1
- 13
- 25