Last active
April 1, 2023 07:46
-
-
Save bfrg/a1fc0ec0a19f4dfad8bb4fd427cfc19e to your computer and use it in GitHub Desktop.
Redirect the output of ":verbose {cmd}" to a quickfix list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" ============================================================================== | |
" Redirect the output of ':verbose {cmd}' to a quickfix list | |
" | |
" Commands: | |
" :Verbose {cmd} | |
" Add items to new quickfix list | |
" | |
" :VerboseAdd {cmd} | |
" Append items to current quickfix list | |
" | |
" Examples: | |
" :Verbose map <leader> | |
" Populate a new quickfix list with the locations of all <leader> mappings | |
" | |
" :VerboseAdd map ] | |
" Append locations of all mappings starting with ] to current quickfix list | |
" ============================================================================== | |
function s:verbose_to_qf(cmd, append) abort | |
let items = [] | |
try | |
let items = execute('verbose ' .. a:cmd) | |
\ ->substitute('^\n*', '', '') | |
\ ->substitute('^\%( Name Args Address Complete Definition\|--- Autocommands ---\)\n', '', '') | |
catch | |
echohl ErrorMsg | |
echomsg matchstr(v:exception, '^Vim:\zs.*') | |
echohl None | |
endtry | |
if empty(items) | |
return | |
endif | |
let qflist = split(items, 'Last set from .\{-}\n\zs') | |
\ ->map({_,i -> matchlist(i, '^\(.\{-}\)\n\tLast set from \(\f\+\) line \(\d\+\)')[1:3]}) | |
\ ->filter('!empty(v:val)') | |
\ ->map({_,i -> {'text': i[0], 'filename': expand(i[1]), 'lnum': i[2]}}) | |
if empty(qflist) | |
return | |
endif | |
let title = (a:append ? getqflist({'title': 0}).title .. ' + ' .. a:cmd : ':verbose ' .. a:cmd) | |
call setqflist([], (a:append ? 'a' : ' '), {'title': title, 'items': qflist}) | |
if exists('#QuickFixCmdPost#grep') | |
doautocmd <nomodeline> QuickFixCmdPost grep | |
endif | |
endfunction | |
command -nargs=+ -complete=command Verbose call s:verbose_to_qf(<q-args>, v:false) | |
command -nargs=+ -complete=command VerboseAdd call s:verbose_to_qf(<q-args>, v:true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
that is nice, but it needs an english locale and a recent vim 8.2