35

Say, I have the following mapping:

map <F4> :execute "vimgrep /" .expand("<cword>") . "/j **" <Bar> cw<CR>

which (recursively) greps the current directory for instances of the word under the cursor and opens these files in the quickfix list window.

From the quickfix window, how do I launch the file that I open into a new tab? Enter just changes my current buffer in the window to that new file.

3 Answers 3

94

Quickfix-window commands respect the switchbuf option when creating the buffer. The switchbuf option has the newtab specifier that instructs Vim to open a new tab page before loading the buffer to switch to. If one adds this key to the option via

:set switchbuf+=newtab

the entries in the quickfix window will be opened in separate tab pages.

There is the usetab specifier that also might be useful in this case. It prescribes Vim to switch to an existing tab page if it contains a window displaying the target buffer, instead of duplicating it in a new tab. If it is desirable, one can throw that in, too:

:set switchbuf+=usetab,newtab

The value of switchbuf also (partially) affects other buffer-switching commands, such as :bfirst, :blast, :sbuffer, :sbnext, and :sbprevious.

1
  • wow. best answer ever. This is exactly what I was hoping to achieve! The usetab option is incredibly convenient as well! Thank you * ∞
    – tester
    Jul 28, 2011 at 5:57
7

How about trying QFEnter plugin?
You can open each item in a new tab or a new vertical/horizontal split window without changing switchbuf option.
It also allows you to open multiple quickfix items at once with a visual selection block.

2
  • I like your plugin. It would be even better if you had all of the mappings the Ack plugin has, possibly the same: github.com/mileszs/ack.vim#keyboard-shortcuts. I also wanted to open a new tab without a quickfix window. Apr 17, 2014 at 8:19
  • Thanks. You can set g:qfenter_enable_autoquickfix to 0 not to open quickfix in a new tab.
    – yssl
    Jun 11, 2014 at 4:10
7
autocmd FileType qf nnoremap <buffer> <Enter> <C-W><Enter><C-W>T

also works if you use:

tab copen

which would otherwise first split the window, even with set switchbuf+=newtab.

See also: https://vi.stackexchange.com/questions/6996/how-to-make-enter-open-new-tabs-for-the-quickfix-window-when-it-is-opened-with

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.