Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open item from quickfix window in vertical split?

Tags:

vim

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?

like image 606
Ben J Avatar asked May 24 '13 20:05

Ben J


3 Answers

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).

like image 194
romainl Avatar answered Oct 19 '22 12:10

romainl


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>
like image 42
LucaB Avatar answered Oct 19 '22 12:10

LucaB


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.

like image 27
yssl Avatar answered Oct 19 '22 12:10

yssl