簡體   English   中英

在垂直拆分中從 quickfix window 打開項目?

[英]Open item from quickfix window in vertical split?

我知道您可以使用 ctrl-w + enter 在新的水平 window 中打開 quickfix 項目。

有沒有辦法在垂直拆分中打開 quickfix window 中的項目?

這是一個快速且肯定不完美的嘗試:

autocmd! FileType qf nnoremap <buffer> <leader><Enter> <C-w><Enter><C-w>L

<leader><Enter>映射僅在quickfix和位置窗口中處於活動狀態。 它在水平窗口( <Cw><Enter> )中打開錯誤/位置,並將其轉換為垂直窗口( <Cw>L )。

QFEnter插件看起來對你有幫助。 它允許在選定的窗口,新的Vert分割窗口,新的分割窗口或新選項卡中打開quickfix項。

QFEnter插件( https://github.com/yssl/QFEnter )非常聰明和棒極了,它可以提供更多的要求,並且可以高度自定義。 它的寫得也很好。

接受的解決方案會導致窗口抖動,因為它首先打開,然后旋轉窗口。

相反,QFEnter插件非常出色,因為功能整潔而且非常流暢。

如果您需要較少的功能(僅限分割打開的功能)或由於某種原因您不能或不會安裝插件,您可以使用以下vimrc片段。 它使用了我從QFEnter插件中學到的相同技術,盡管是以非常簡單的方式,並且僅使用CtrlP( <Cv><Cx> )提供的相同快捷方式提供垂直和水平分割。

" This is only availale in the quickfix window, owing to the filetype
" restriction on the autocmd (see below).
function! <SID>OpenQuickfix(new_split_cmd)
  " 1. the current line is the result idx as we are in the quickfix
  let l:qf_idx = line('.')
  " 2. jump to the previous window
  wincmd p
  " 3. switch to a new split (the new_split_cmd will be 'vnew' or 'split')
  execute a:new_split_cmd
  " 4. open the 'current' item of the quickfix list in the newly created buffer
  "    (the current means, the one focused before switching to the new buffer)
  execute l:qf_idx . 'cc'
endfunction

autocmd FileType qf nnoremap <buffer> <C-v> :call <SID>OpenQuickfix("vnew")<CR>
autocmd FileType qf nnoremap <buffer> <C-x> :call <SID>OpenQuickfix("split")<CR>

內置設置:set switchbuf=vsplit也應該有效(至少在較新的 vim 版本上)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM