빠른 수정 창에서 별도의 빠른 수정 창으로 줄 이동

빠른 수정 창에서 별도의 빠른 수정 창으로 줄 이동

에서 검색 결과를 집계하기 위해 빠른 수정 창을 사용합니다 grep. 그러나 때로는 일부 결과를 다시 확인하고 싶을 때도 있습니다. 줄을 붙여넣고 나중에 참조할 수 있는 또 다른 빠른 수정 창을 만드는 방법이 있습니까?

감사해요

답변1

Vim은 다음과 함께 배송됩니다.:help cfilter-plugin그게 당신을 할 수 있습니다제거하다더 이상 원하지 않는 빠른 수정 항목이 있으므로 반대 방향으로 작동합니다.

또는 Vim이 해당 스택을 유지 관리하므로 현재 항목을 기반으로 새 빠른 수정 목록을 만들 수도 있습니다(cp.: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.

플러그인 솔루션

.다음은 카운트, 반복을 통한 반복 , 시각적 모드 및 위치 목록 항목을 빠른 수정 목록으로 수집하는 기능 도 지원하는 완전한 플러그인입니다 . 그것은 내 필요합니다잉고 라이브러리 플러그인, 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

관련 정보