Tuesday, August 15


One thing I've really missed since the days of having fluxbox as my window manager was tabbed windows. It was really useful for chaps like me who have tons of windows open and poor innate visual organization skills. Well vim 7 doesn't quite bring back those glory days (not that I miss XF86Config even a trifle), but it certainly greatly improves the experience with many files open.

Tabs augment (but do not replace) the existing vim buffer model. Each tab is a separate window—actually a separate page of windows if you must know—thus each tab can, if desired, contain several windows and buffers. I'm not sure how useful that is, but it could be interesting if you like to split your windows to view multiple buffers simultaneously.

Normally, if you launch vim and specify multiple files to edit on the command line, it puts all of the files into separate buffers. Now, you can tell vim, using the -p option to put each file in it's own tab instead. The result is easier navigation between files. I've got vim aliased to vim -p now so it uses tabs by default for multiple files.

Once in vim, when you use the :e command, it still opens a new buffer in the current window. To instead open the file in a new tab, use :tabe. To navigate between tabs, you can use the mouse, or the :tabp and :tabn commands. I find those commands pretty tedious, so I've added the following key mappings to my .vimrc file:

"tab mappings
nmap <D-1> 1gt
nmap <D-2> 2gt
nmap <D-3> 3gt
nmap <D-4> 4gt
nmap <D-5> 5gt
nmap <D-6> 6gt
nmap <D-7> 7gt
nmap <D-8> 8gt
nmap <D-9> 9gt
nmap <D-t> :tabnew<CR>
nmap <D-w> :tabclose<CR>
nmap <C-D-\> :tabp<CR>
nmap <C-D-]> :tabn<CR>

This gives me [cmd]+1 through [cmd]+9 to jump directly to a tab, [cmd]+t to open a fresh tab, [cmd]+w to close one and [cmd]+left and [cmd]+right to go to the previous and next tabs respectively. This makes navigating vim tabs more-or-less like iterm, consistency, it is good for ui!

Here's a link with more ideas for key mappings. Also check out the full vim documentation on tabs.