Reputation: 3167
I am wondering how I can open all of the current buffers in vi(m) in new tabs. I know that you can edit your vimrc file to do something like this, but I'd prefer just to be able to run a command when needed. I can do it manually by chaining the new tab and open buffer commands, such as:
:tabnew | b 1
But I would prefer a more automatic approach.
Upvotes: 44
Views: 16237
Reputation: 393769
The way to go is:
:tab sball
From the help:
"sball: Rearrange the screen to open one window for each buffer in the buffer list... When the |:tab| modifier is used new windows are opened in a new tab, up to 'tabpagemax'."
Without the |:tab| modifier, it open each buffer in split view.
:sball
or to open at most 6 of them
:6sball
etc.
Upvotes: 63
Reputation: 1104
[I would have commented on the accepted answer above but haven't enough rep points.]
For me the accepted answer leaves the new tabs without syntax highlighting, if they are buffers that have never been previously viewed. (To reproduce - select a number of XML files, choose Edit with Single Vim in Windows Explorer, try it from there.) I don't know why this happens so my solution is just to turn syntax highlighting on again.
I also find it annoying that the last buffer ends up with two tabs, so my solution is to move to the last tab and close it.
:bufdo tab split
:tablast
:tabclose
:syntax on
So in a mapping,
:map ,bt :bufdo tab split<CR>:tablast<CR>:tabclose<CR>:syntax on<CR>
Upvotes: 10
Reputation: 2494
you can assign a mapping to this command:
:bufdo tab split
finally, to map this:
map ,bt :bufdo tab split<CR>
greets
Upvotes: 38