24

I know you can open quickfix items in a new horizontal window with ctrl-w + enter.

Is there a way to open an item from the quickfix window in a vertical split?

Ben J
  • 2,252
  • 4
  • 23
  • 30
  • 5
    You could do `L` or `H` to turn the opened window into a vertical window. – romainl May 24 '13 at 20:43
  • I'm looking for a way to do it directly from the quickfix window. – Ben J May 24 '13 at 20:49
  • There's no built-in way to do that: you have only `` and ``. You can't really avoid creating a custom mapping, here. – romainl May 24 '13 at 20:51
  • Misunderstood the question and almost wrote an answer for "How to open the quickfix window in vertical split". Any misguided souls who found this thread for this, just use `:vert copen` and resize it (see [this thread](https://vi.stackexchange.com/questions/514/how-do-i-change-the-current-splits-width-and-height) on the how). – toraritte Jan 16 '19 at 16:40

4 Answers4

13

Here is a quick and certainly imperfect attempt:

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

The <leader><Enter> mapping is active only in the quickfix and location windows. It opens the error/location in an horizontal window (<C-w><Enter>) and turns it into a vertical window (<C-w>L).

romainl
  • 186,200
  • 21
  • 280
  • 313
10

QFEnter plugin looks helpful for you. It allows to open a quickfix item in a selected window, in a new vert split window, in a new split window or in a new tab.

yssl
  • 101
  • 1
  • 2
  • The default behavior of opening an entry from the quickfix on a random window bothers me too. Thank you for providing this great plugin! – mMontu Jan 09 '14 at 11:18
8

The QFEnter plugin (https://github.com/yssl/QFEnter) is really clever and awesome, it does what asked and much more, and it's highly customisable. It's also very well written.

The accepted solution causes a jerking of the windows, because it first opens, and then rotates the windows.

The QFEnter plugin instead is much superior, because the functionality is neat and completely smooth.

In case you need less functionality (exclusively the ability to open in a split) or for some reason you can't or won't install a plugin, you can use the following vimrc snippet. It uses the same technique I learned from the QFEnter plugin, albeit in a very simplified manner and only to provide vertical and horizontal splits using the same shortcuts offered by CtrlP (<C-v> and <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>
LucaB
  • 258
  • 4
  • 5
1

An inbuilt setting :set switchbuf=vsplit should also work (at least on newer vim versions).