Question

I have the following setting in my ~/.vimrc

set hidden
set switchbuf+=usetab,newtab

The second line allows me to open files from QuickFix window in a new tab when I press Enter. Everything works fine, but when a new file is opened in a new tab, it results in an new empty buffer in the buffer list.

Is it possible to have the above feature without this new empty buffer?

I am using the following version of macvim

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Nov 25 2013 10:33:00)
MacOS X (unix) version
Included patches: 1-52
Compiled by Homebrew
Was it helpful?

Solution

You're seeing an implementation detail. In buflist_getfile() (found in src/buffer.c), the switchbuf=newtab is handled by this code:

if (swb_flags & SWB_NEWTAB)     /* Open in a new tab */
    tabpage_new();

Basically, Vim performs a :tabnew followed by the :edit file command, whereas a :tabedit file would be better, because it avoids the empty tab page (which has to display something, so an empty buffer is created).

Admittedly, this is mostly a cosmetic issue, but I can understand that it bothers you. You can raise this on the vim_dev mailing list; ideally with a patch that fixes the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top