vim - howto close all buffers in the current tab? - vim

I know that using a command like:
:%bdelete
Using this command I can close all buffers, in all tabs, what I'd like to do is to close all buffers open in the current tab, is that possible?
Usage:
What I'd like to do, is to open ViM and load :VSTreeExplorer and then open related files in the same window switching between them using :next and :previous and then open other files a new tab (with VSTreeExplorer as well), when I need to clean one of the tabs, I would like to use whatever command that closes buffers in the current tab.
For now, what I do is use :%bd and then open the VSTreeExplorer and start over...
Thanks

If you're done with a tab you can just use :tabclose.

:windo bd will delete all buffers in the current tab.

Buffers are global to the Vim instance, not confined to a specific tab page. A tab page is simply a way to organize windows and windows are simply a way to display a buffer. Zero or more windows (and therefore tab pages) can display the same buffer. Getting used to this concept should help your workflow in Vim.
The Vim wiki has a couple pages that give some more explanation and tips for using tab pages.

Related

What Is the Purpose of the tabclose Command In Vim?

If you have multiple tabs, giving the :tabclose command "closes" the tab but does not delete it from the buffer list, so the tab still appears in the tab menu; however it is inaccessible. To fully remove the tab, one would have to provide the :bd command. I'm not sure what the purpose is of closing a tab without deleting it from the buffer-list. From what I can gather from the help document, tabpage.txt, is that you aren't even able to reopen the closed tab, although, I could very well be wrong on that. I am rather confused on the purpose of this command; It seems more efficient to just use :bd and not bother with :tabclose.
:tabclose tries to close all windows on a tab. If it succeeds then the tab is also closed.
Buffer is neither tab nor window. :bdelete is neither :bunload nor :bwipeout. 1 2 3 4
If you have multiple tabs, giving the :tabclose command "closes" the tab but does not delete it from the buffer list, so the tab still appears in the tab menu; however it is inaccessible.
You are confusing tab pages, windows, and buffers.
:tabclose closes the tab page. This also closes the windows contained in that tab page but the only effect it has on the buffers displayed in those windows is to hide them.
What is remaining after :tabclose is the buffers that were displayed in the windows contained by the tab page you closed. Since the buffer list is global and not tied in any way to either tab pages or windows, this is perfectly normal and expected.
To fully remove the tab, one would have to provide the :bd command.
No. The tab page was fully removed after :tabclose. :bd only "deletes" buffers.
I'm not sure what the purpose is of closing a tab without deleting it from the buffer-list.
Your tab page is not in the buffer list so what you describe only makes sense if you confuse tab pages, windows, and buffers.
See this answer of mine for more background tab pages, windows, and buffers.

Better Tab Navigation in gVim

How can I get tabs in gVim to work like they do in most good IDEs? I say gVim specifically because that is the version of Vim that I use but I am open to alternatives.
I want the following things for my tabs:
Ctrl+Tab goes to the MRU (most recently used) tab.
Holding down Ctrl and then pressing Tab multiple times continues to change to the next most recently used tab every time you press Tab.
When ctags are built and working and you press Ctrl+], if this takes you to a different file it should open that file in a new tab or if a tab with that file is already open it should switch to that one.
Easy tab reordering with the mouse just by dragging them around.
I am posting all these as a single question because I am hoping there is a good single solution that will do all or most of these things instead of having to hack each customization in individually. I would think this would be the preferred behavior by most of us.
Vim has no built in MRU. There is at least one plugin for that, though, but I've never used it.
The tabs in Vim are not the same as the tabs in your IDE, they are more like perspectives. The equivalent of your IDE's tabs in Vim are buffers and "(split)windows". There are a number of ways to work with buffers including some native ones and a number of third party plugins. Some of these plugins have MRU-like features.
The Vim wiki has a bunch of pages about tabs.

more intelligent global bookmarks in vim

Here's how global bookmarks work.
Let's say I have two tabs in my vim session. One showing foo.txt, one showing bar.txt. I go to line 10 in foo.txt and hit mA
Then I go to the other tab, showing bar.txt. I hit `A, and the workspace on that tab opens foo.txt, putting my cursor on line 10.
So now I have two tabs, both showing foo.txt. This is less than ideal.
How I want it to work is, if one of my active workspaces on any tab is showing the file I the bookmark system is trying to navigate too, move my focus to that tab. If the file isn't open, sure - open it in my active workspace.
Is there any way to make this possible?
Thanks!
This is not a problem with Vim's global bookmarks. It's a problem with Vim's tabs.
In most text editors, tabs serve as a list of currently open files, but in Vim, the buffer list serves this purpose. If you think of a tab in Vim as being like a saved layout for split windows, then you'll meet less friction. This answer sums it up nicely, and I made a screencast to try and explain how tabs can be used.
Here is a script that answers your initial question. But as far as I'm concerned, nelstrom is right: tabs are not meant to contains the others files, but other layouts.
How do I jump to markers within different tabs in vim?

Prevent opening files inside NERDTree or MiniBuffExplorer windows in Vim

I find myself opening files inside the wrong window in Vim — sometimes the NERDTree or MiniBuffExplorer — and it’s really throwing me off.
I’m sure it’s happening because my cursor is mistakenly focused inside one of these windows, but is there anything I can add to my .vimrc file to prevent this from happening?
I finally found the solution to this annoyance in the MiniBufExplorer source comments. It looks like this feature has been available since version 6.2.8 (release 2004-06-07):
If you use other explorers like TagList you can (As of 6.2.8) put:
let g:miniBufExplModSelTarget = 1
into your .vimrc in order to force MBE to try to place selected
buffers into a window that does not have a nonmodifiable buffer.
The upshot of this should be that if you go into MBE and select
a buffer, the buffer should not show up in a window that is
hosting an explorer.
It's possibly related to the setting of mousefocus. From :help mousefocus
The window that the mouse pointer is
on is automatically activated. When
changing the window layout or window
focus in another way, the mouse
pointer is moved to the window with
keyboard focus. Off is the default
because it makes using the pull down
menus a little goofy, as a pointer
transit may activate a window
unintentionally.

VIM Project and Tabs

Is there a possibility to combine the Project Plugin with Tabs?
If i open a file in my Project Explorer, i want to open it in a new tab ... :)
You have to hack this plugin yourself (I do not think it would be difficult) or email the author and kindly ask him to do it.
I would also suggest NERDTree as a Project replacement (it can open files in tabs).
For open file of project in other tab use
Leader T
\T
I was having the same issue. For now I'vee learned to use buffers.
To expand on the buffers post above, when you open a new file the Project plugin hides the previous file but it is still an active buffer. ':ls' will list the buffers, switch to a buffer with ':b #' where # is the number of the buffer or split the screen and open a buffer with ':sb #'. Not quite as convenient as tabs but it works until a better solution comes up.
If you open a new buffer window, you can click to open in that buffer.
If you have macVim or gVim of some sort, you can open a finder/explorer window at the project's tree and drag and drop files into windows/tabs.
I had this same desire, so I created a portable configuration called Vim.ana.
It doesn't have many opinions that you can't change easily in the .vimrc
Sauce on layout at the project homepage

Resources