Vim Tips Wiki
Advertisement
Tip 1317 Printable Monobook Previous Next

created August 25, 2006 · complexity basic · author Groleo Marius · version n/a


To open each buffer in its own tabpage, add this to your vimrc:

:au BufAdd,BufNewFile * nested tab sball

See also

Comments

I modified it to the following so that every file I open from the command line with Vim also opens in its own tab:

:au BufAdd,BufNewFile,BufRead * nested tab sball

However when I do :e! to reload the current buffer, it always jumps to the last opened tab and reloads it.


I would like to get each tab bound to a buffer. This hint is one step closer to that, but not quite there yet. Say I am browsing code and I hit Ctrl-] to jump to a class definition which opens up a new file in a new tab, then I hit Ctrl-T to go back to the previous code. Now I have two tabs that have the same file loaded. Is there any way to catch the change buffer event, then find the tab that already has that buffer loaded and switch to that tab? To me this seems like the natural way to use tabs, at least it's how I'm used to using them from all other programs I've ever used tabs in. It seems funny that there is no option to have them work in this way in Vim.


This seems to do horrid things when I reference the help (e.g. :help :auto): from 1 buffer containing the file I'm editing, I end up with 2, each in their own tab. My original file has been hidden, and I've two windows on the helpfile autocmd.txt - one pointing at start-of-file, the other pointing to the referenced tag.


It also does not work nicely if you use the :Explore command to navigate the file system (which I do all the time). Every time you list a new directory, it opens a new tab. Needless to say the tabs pile up quickly.

Warning: Frustrated Rant Ahead: I have to say that I'm really disappointed in the tab functionality in Vim 7.0. I think it is extremely unintuitive in the way it works. And it's a big pain to jump through so many hoops like this, just to try to get it to work the way it should in the first place.

I was expecting that every file would open in a new tab and everything would just work. Maybe there would be a setting to turn on tabs and that would be it. Alas, no. You have to configure this obvious tab behaviour yourself. And after many tweaks to my .vimrc file and hours of searching the Vim help, Vim online, the Vim mailing lists and Google, modifying this and tweaking that, I still do not have a satisfactory solution. I've come close, but there's always something that doesn't work.

Along the way I noticed that everyone is trying to do the same thing. Everyone just wants to open a tab for each buffer automatically and have it just work. It seems fairly obvious that tabs should work this way. It surprises me that the developers missed this. End Rant.


I'm not sure why there's such a problem dealing with tabs - at least I don't find them difficult.

When I open a couple files and I want them to be in individual tabs, I add '-p' to the command: gvim -p file1 file2 ... and they all open in their own tabs.

Or, if I don't want that behavior, I omit the '-p', and Vim opens them in buffers but doesn't display them, and then, if I decide I want to split a window and show a particular combination of files in the same tab (or window) I can using the standard (old) splitting methods.

If I have a particular buffer I want to open in a tab, after I've loaded it, I use ':tabfind filename' and Vim opens that buffer in a tab. Or, I just open a blank tab (':tabnew') then do a :bu to pull that file into the tab.


This is incompatible with the tag list. If I for example wish to open a tag list (I remapped <F8> for this) then it basically open the tag list in a tab but the file itself is not unreachable. How to make this opening of new files in tabs compatible with the tag lists? (e.g. python tag lists) thanks! --Resemele

Please edit the "Comments" section of the tip if you have a comment about the tip content.
The "report a problem" link is to report problems with the wiki: broken rendering, spam, etc (I have copied the text from the problem report to the above comment).
Presumably by "tag list" you are referring to a script? You would need to make it a little clearer what you are using, and what the problem is. However, I think that your question is not related to the implementation of this tip? If I am correct, you need to review the information below to see better places to get help. --JohnBeckett 07:18, 31 December 2008 (UTC)
We don't encourage questions about using Vim on the wiki because they distract from the work of improving the tip collection. Of course, feel free to comment if you have questions about or see deficiencies in a tip, but please see how to ask questions for issues regarding Vim itself. This comment was added on 2008-12-31 and will be removed after a week.

Here is what I use in my .vimrc. I hope it is helpful:

"--------------------
" Function: Open tag under cursor in new tab
" Source:   http://stackoverflow.com/questions/563616/vimctags-tips-and-tricks
"--------------------
map <C-\> :tab split<CR>:exec("tag ".expand("<cword>"))<CR>
"--------------------
" Function: Remap keys to make it more similar to firefox tab functionality
" Purpose:  Because I am familiar with firefox tab functionality
"--------------------
map     <C-T>       :tabnew<CR>
map     <C-N>       :!gvim &<CR><CR>
map     <C-W>       :confirm bdelete<CR>

Advertisement