
Utilizo la ventana Quickfix para agregar resultados de búsqueda de grep
. Sin embargo, a veces quiero poder recuperar algunos de los resultados. ¿Hay alguna manera de crear otra ventana de corrección rápida donde pueda pegar las líneas y poder consultarlas más tarde?
Gracias
Respuesta1
Vim se envía con el:help cfilter-plugin
eso te permiteeliminarentradas de corrección rápida que ya no desea, por lo que funciona al revés.
Alternativamente, puede crear una nueva lista de soluciones rápidas basada en la actual, ya que Vim mantiene una pila de ellas (cp.:help :colder
). Sin embargo, si desea seleccionar varias entradas de forma interactiva, hacerlo de un lado a otro, crear una nueva lista la primera vez y recuperar esa lista más nueva las siguientes veces es engorroso.
Entonces podrías usar inteligentemente ellocation-list
en cambio; Funciona igual que Quickfix, pero es local en una ventana (aquí: la ventana Quickfix).
Para copiar toda la entrada actual sin volver a analizarla, el nivel bajogetqflist()
ysetloclist()
puede ser usado:
:call setloclist(0, [getqflist()[line('.') - 1]], 'a')
| | | |
| | | +-- ... and append
| | +-- select the current one
| +-- entries from the quickfix list
+-- Location list for the current window ...
Puede vincularlo a una clave anteponiendo nnoremap <LocalLeader>ql
y colocando la definición de mapeo ~/.vim/after/ftplugin/qf.vim
.
Solución de complemento
Aquí hay un complemento completo que también admite contar, repetir mediante .
, modo visual y recopilar entradas de la lista de ubicaciones en la lista de corrección rápida. requiere micomplemento de biblioteca ingo, 1.040 o superior, actualmente solo está disponible como una instantánea de desarrollo enGitHub. También se puede copiar en ~/.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