クイックフィックスウィンドウから別のクイックフィックスウィンドウに行を移動する

クイックフィックスウィンドウから別のクイックフィックスウィンドウに行を移動する

からの検索結果を集約するためにクイックフィックス ウィンドウを使用していますgrep。ただし、結果の一部に戻りたい場合があります。行を貼り付けて後で参照できる別のクイックフィックス ウィンドウを作成する方法はありますか?

ありがとう

答え1

Vimには:help cfilter-pluginそれはあなたが取り除く不要になったクイックフィックスエントリを削除する場合は、その逆の手順になります。

あるいは、Vim がそれらのスタックを維持しているので、現在のクイックフィックス リストに基づいて新しいクイックフィックス リストを作成することもできます (cf.:help :colderただし、複数のエントリを対話的に選択する場合、最初に新しいリストを作成し、次回はその新しいリストを呼び出すという操作を繰り返すのは面倒です。

だから、あなたは賢くlocation-list代わりに、quickfix と同じように動作しますが、ウィンドウ (ここでは quickfix ウィンドウ) に対してローカルです。

現在のエントリ全体を再解析せずにコピーするには、低レベルのgetqflist()そしてsetloclist()に使える:

:call setloclist(0, [getqflist()[line('.') - 1]], 'a')
      |              |           |                 |
      |              |           |                 +-- ... and append
      |              |           +-- select the current one
      |              +-- entries from the quickfix list
      +-- Location list for the current window ...

nnoremap <LocalLeader>qlを先頭に追加し、マッピング定義を に配置することで、これをキーにバインドできます~/.vim/after/ftplugin/qf.vim

プラグインソリューション

カウント、繰り返し.、ビジュアルモード、クイックフィックスリストへの場所リストエントリの収集もサポートする完全なプラグインです。ingo-library プラグイン、1.040以上、現在は開発スナップショットとしてのみ利用可能GitHub以下にコピーすることもできます~/.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

関連情報