Suppose I have started vim like this:
vim foo bar
Now I decide that I want each of those files in its own tab. Is there a way to do that without exiting vim and adding the
-p option to my command line?
When you start vim like that, you don't get a vim client, the text editor is using the terminal or cmd prompt - the two files are in two different buffers. Use
The %a is the active buffer. You can use
If you have 2 files loaded & no tabs (yet), you can,
If you want to always have buffers loaded into their own tabs, check out this article.
You wish to open a buffer in a new tab ?
Split up the screen (Ctrl-W s), take up a window, and Ctrl-W T
A better way to accomplish what OP asked for is this:
This will open each buffer into a tab of its own, no matter how many there are. If you use this much, it's easy to make into a mapping in your .vimrc. Combined with something like this little vim plugin the following will open every item from
Of course, when resorting to a plugin it would be easy enough to modify it to open the quickfix list contents in directly into tabs.
UPDATE: I've really got to give a shout-out to ggustafsson's comment below. It's far and away the best answer of the lot and beautifully illustrates Vim's tendency towards compositional behavior. The suggestion is:
1. Open two files in Vim.
$ vim foo bar
2. Check the numbers of buffers.
:ls 1%a "foo" 2 "bar"
3. Chain two commands:
:tabnew | b 2
First you'll need to know the buffer id of the buffer you wish to open in a new tab. You can find this out with the
Once you have the id, you can easily open it in a new tab using:
Just add some point which other guys didn't mention.
If have multiple window,
4 keystrokes or 7 keystrokes.
If use CtrlP plugin, also could use "CtrlPBuffer", then with
With shortcut of "CtrlPBuffer", 4 keystrokes or more.