switching between tabs in vim with vim-airline

Om3ga picture Om3ga · Feb 28, 2015 · Viewed 13.2k times · Source

I am using vim-airline plugin which works pretty good however, the only way to switch between tabs is to user :bp or :bn which is shortcuts for :bprevious or :bnext. The problem with this is that if I am on first tab and want to switch to the last tab i.e. 10th tab then I have to type :bn ten times to get there. How can I switch directly? Maybe something pressing arrow keys would be beneficial.

Answer

romainl picture romainl · Feb 28, 2015

Your problem is that you installed a plugin designed to obfuscate Vim's regular commands and workflows without even knowing those regular ways. The shortcut you took lead you to a dead-end so your only reasonable solution is to go back to the main road and learn Vim properly, without training wheels and crutches.

So… from your question, it seems you are using Airline's so-called "smarter tabline" which displays your open buffers in a fake tabline.

If it was a real tabline, they would actually be tab pages and you would move between them with their own set of commands.

But they are buffers and yes, you are supposed to move between them with these commands:

:bnext
:bprevious
:bfirst
:blast
:b10
:b <buffer-name>

which can all be mapped for your convenience, of course.

But… that plugin doesn't show buffer numbers, so you can't use :b10 to jump reliably to the tenth buffer in your fake "tabline" so that's one less tool in your tool-belt.

And some special buffers, like the quickfix list, can be reached with :bn/:bn without — probably — being listed in your fake "tabline" so that makes your fake "tabline" a rather poor abstraction, even without considering the glaring limitations of tabs in general.

And there's the idiosyncratic behavior of that fake "tabline" which becomes a semi-real "tabline" when you actually use tab pages.

Conflating two very different — and powerful in their own ways — concepts into a single bastardized one is not really a good idea.

I suggest you disable that option and use buffers and tab pages as they are meant to be used.

Reference:

:help buffers
:help tab-page