Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Vim quickfix list launch files in a new tab?

Tags:

vim

tabs

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.

like image 236
tester Avatar asked Jul 28 '11 00:07

tester


1 Answers

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.

:set switchbuf+=usetab,newtab 

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

like image 80
ib. Avatar answered Sep 22 '22 02:09

ib.