Enhanced buftabs Vim Plugin

After a couple of days using my bufpos vim plugin together with buftabs, I realized I didn’t need the buffer numbers in the status line (I can always get them with :ls), but their position number would have been very useful.

So here is my modified version with these three changes:

  • the tab numbers indicate the the number you have press to get there instead of the buffer number
  • improved autocmd settings to better synchronize the ! modified flag
  • different filename shortening mode, now it is displayed with a path relative to the current or home directory (don’t set g:buftabs_only_basename to get that)

I have contacted the buftabs author and the last two will be in the next buftabs release too.

Tabs in Vim and My First Plugin

One of the most talked about features of Vim7 are tabs, but I don’t like them very much, I think they should have been given a different name. They could have been called layouts, for example, because they are very different from what most people expect and much more similar to Eclipse’s perspectives or NetBeans workspaces than to Firefox tabs.

I find buffers, which have been in Vim since pretty much forever, are a very convenient way to edit multiple files. You just have to tune them a bit.

First, you absolutely have to set the hidden option, so you can switch between buffers without being forced to save them, and then you need some key mappings:

set hidden
map <C-TAB> :bnext!<CR>
map <C-S-TAB> :bprev!<CR>
map <C-\> :b#<CR>

Use Ctrl-Tab and Ctrl-Shift-Tab to navigate through the list of open buffers and Ctrl-\ to quickly toggle between two open files.

After using this setup for quite some time, about a week ago I found buftabs, a simple plugin that displays the open buffers in the status line. I like simple plugins, my rule is that they have to be useful without me having to actually learn to use them or even remember they are there.

set laststatus=2
let g:buftabs_in_statusline=1

I then added two more mappings to navigate through buffers, to better match the visual representation buftabs provides.

map <C-b> :bprev!<CR>
map <C-n> :bnext!<CR>

With these switching buffers is even easier, as you have a visual indication of which buffer you are going to activate.

Just one last piece was missing from this picture: most tabs implementations allow you to directly activate a tab by pressing the Alt key and a number, like Firefox, for example.

So here comes my first Vim script ever: bufpos is a very simple script that maps Alt-number keys to activate buffers.

Note that you don’t have to use the buffer number buftabs puts beside the file name, but the position in the buffers list.

Vim Tango color scheme

Things you do at the airport while waiting for the cute girl to call the boarding…

Finding that a Tango color scheme for my terminal was a nice idea, I made one for my Vim too.

screenshot

To use the Vim Tango color scheme you have to place the tango.vim file in the ~/.vim/colors/ directory and colorscheme tango in your ~/.vimrc.