
Ich verwende das Quickfix-Fenster zum Aggregieren von Suchergebnissen grep
. Manchmal möchte ich jedoch auf einige der Ergebnisse zurückgreifen können. Gibt es eine Möglichkeit, ein weiteres Quickfix-Fenster zu erstellen, in das ich die Zeilen einfügen und später darauf verweisen kann?
Danke
Antwort1
Vim wird mit dem:help cfilter-plugin
das lässt SieentfernenQuickfix-Einträge, die Sie nicht mehr benötigen, also funktioniert es auch andersherum.
Alternativ können Sie eine neue Quickfix-Liste auf Grundlage der aktuellen erstellen, da Vim einen Stapel davon verwaltet (vgl.:help :colder
). Wenn Sie jedoch interaktiv mehrere Einträge auswählen möchten, ist dieses Hin und Her, das Erstellen einer neuen Liste beim ersten Mal und der erneute Aufruf dieser neueren Liste bei den folgenden Malen umständlich.
So könnte man geschickt dielocation-list
stattdessen funktioniert es genau wie Quickfix, ist aber lokal auf ein Fenster beschränkt (hier: das Quickfix-Fenster).
Um den gesamten aktuellen Eintrag zu kopieren, ohne ihn erneut zu analysieren, muss die Low-Level-getqflist()
Undsetloclist()
kann verwendet werden:
:call setloclist(0, [getqflist()[line('.') - 1]], 'a')
| | | |
| | | +-- ... and append
| | +-- select the current one
| +-- entries from the quickfix list
+-- Location list for the current window ...
Sie können dies an einen Schlüssel binden nnoremap <LocalLeader>ql
, indem Sie voranstellen und die Zuordnungsdefinition einfügen ~/.vim/after/ftplugin/qf.vim
.
Plugin-Lösung
Hier ist ein komplettes Plugin, das auch Zählen, Wiederholen über .
, visuellen Modus und das Sammeln von Standortlisteneinträgen in der Quickfix-Liste unterstützt. Es erfordert meineIngo-Bibliotheks-Plugin, 1.040 oder höher, derzeit nur verfügbar als Dev-Snapshot aufGitHub. Es kann auch kopiert werden in ~/.vim/after/ftplugin/qf.vim
:
function! s:Mapping( mappingType, sourceType, targetType, startLnum, endLnum ) abort
if ingo#window#quickfix#IsQuickfixList(1) != a:sourceType
call ingo#err#Set(printf('Not in a %s list', (a:sourceType == 1 ? 'quickfix' : 'location')))
return 0
endif
let l:qfEntries = ingo#window#quickfix#GetList()[(a:startLnum - 1) : (a:endLnum - 1)]
if empty(l:qfEntries)
call ingo#err#Set('No entries')
return 0
endif
silent call ingo#event#Trigger(printf('QuickFixCmdPre %scopy', ingo#window#quickfix#GetPrefix(a:targetType)))
call ingo#window#quickfix#SetOtherList(a:targetType, l:qfEntries, 'a')
silent call ingo#event#Trigger(printf('QuickFixCmdPost %scopy', ingo#window#quickfix#GetPrefix(a:targetType)))
echomsg printf('%s entr%s copied to %s', len(l:qfEntries), (len(l:qfEntries) == 1 ? 'y' : 'ies'), ingo#window#quickfix#GetName(a:targetType))
let l:mappingPrefix = "\<Plug>(QuickfixCopyTo" . a:mappingType
silent! call repeat#set(l:mappingPrefix . 'Lines)', len(l:qfEntries))
silent! call visualrepeat#set(l:mappingPrefix . 'Selection)', len(l:qfEntries))
return 1
endfunction
" [N]<LocalLeader>qc Copy the current [N] location list entries to the
" quickfix list.
" [N]<LocalLeader>ql Copy the current [N] quickfix entries to a location list
" (for the current quickfix window).
nnoremap <buffer> <silent> <Plug>(QuickfixCopyToQuickfixLines) :<C-u>if ! <SID>Mapping('Quickfix', 2, 1, line('.'), line('.') + v:count1 - 1)<Bar>echoerr ingo#err#Get()<Bar>endif<CR>
xnoremap <buffer> <silent> <Plug>(QuickfixCopyToQuickfixSelection) :<C-u>if ! <SID>Mapping('Quickfix', 2, 1, line("'<"), line("'>"))<Bar>echoerr ingo#err#Get()<Bar>endif<CR>
nnoremap <buffer> <silent> <Plug>(QuickfixCopyToLocListLines) :<C-u>if ! <SID>Mapping('LocList', 1, 2, line('.'), line('.') + v:count1 - 1)<Bar>echoerr ingo#err#Get()<Bar>endif<CR>
xnoremap <buffer> <silent> <Plug>(QuickfixCopyToLocListSelection) :<C-u>if ! <SID>Mapping('LocList', 1, 2, line("'<"), line("'>"))<Bar>echoerr ingo#err#Get()<Bar>endif<CR>
if ! hasmapto('<Plug>(QuickfixCopyToQuickfixLines)', 'n')
nmap <LocalLeader>qc <Plug>(QuickfixCopyToQuickfixLines)
endif
if ! hasmapto('<Plug>(QuickfixCopyToQuickfixSelection)', 'v')
xmap <LocalLeader>qc <Plug>(QuickfixCopyToQuickfixSelection)
endif
if ! hasmapto('<Plug>(QuickfixCopyToLocListLines)', 'n')
nmap <LocalLeader>ql <Plug>(QuickfixCopyToLocListLines)
endif
if ! hasmapto('<Plug>(QuickfixCopyToLocListSelection)', 'v')
xmap <LocalLeader>ql <Plug>(QuickfixCopyToLocListSelection)
endif