在垂直分割窗口中打开快速修复窗口的项目?

24

我知道你可以使用 ctrl-w + enter 在一个新的横向窗口中打开 quickfix 项。

是否有一种方法可以在垂直分割中打开 quickfix 窗口中的项目?

注:无需更改任何 HTML 标签。

5
你可以使用 <C-w>L<C-w>H 将当前打开的窗口变为纵向窗口。 - romainl
我正在寻找一种直接从快速修复窗口执行此操作的方法。 - Ben J
没有内置的方法可以做到这一点:你只有 <C-w><Enter><Enter>。在这里,你真的无法避免创建自定义映射。 - romainl
误解了问题,差点写了一个关于“如何在垂直分割中打开快速修复窗口”的答案。任何误入歧途的人如果找到这个线程,请使用:vert copen并调整大小(请参见此线程上的说明)。 - toraritte
5个回答

13

这里是一个快速而且不完美的尝试:

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

<leader><Enter> 映射仅在 quickfix 和 location 窗口中启用。它会在一个水平窗口中打开错误/位置 (<C-w><Enter>),并将其转换为垂直窗口 (<C-w>L)。


1
谢谢!我没有意识到quickfix窗口有自己的文件类型。 - Ben J

10

QFEnter插件看起来对你很有帮助。 它可以让你在选定的窗口、新的垂直分割窗口、新的分割窗口或新的标签页中打开一个快速修复项目。


默认情况下,在随机窗口中打开快速修复条目的行为也让我感到困扰。感谢您提供这个很棒的插件! - mMontu

8
QFEnter插件(https://github.com/yssl/QFEnter)非常聪明和棒,它能够执行所需的任务以及更多,并且高度可定制。它也写得非常好。
已接受的解决方案会导致窗口抖动,因为它首先打开窗口,然后旋转窗口。
相比之下,QFEnter插件要优越得多,因为其功能整洁而完全平滑。
如果您需要较少的功能(仅需要在分割中打开),或者由于某种原因您不能或不想安装插件,则可以使用以下vimrc片段。它使用我从QFEnter插件学到的相同技术,虽然方式简化了很多,但只提供使用CtrlP提供的相同快捷键(<C-v><C-x>)来提供垂直和水平拆分。
" 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>

1

内置设置:set switchbuf=vsplit也应该可以工作(至少在较新的vim版本中)。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接