What Is the Purpose of the tabclose Command In Vim? - 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.

Related

gVim switching to the wrong tab

I use Vim besides programming for blogging and commenting. The latter leads to a few hundred open textbuffers in tabs in gVim to be able to search for useful text over all comments and copy it into a new comment. I save the whole session when exiting gVim for auto-opening the buffers when restarting it.
Today, with 270 buffers open in 257 tabs, I ran into a weird problem when switching the tabs with the mouse (tabpagemax is set to 1000, but the fact that this error occured around the 256th tab is a bit suspicious - Is there some limiting setting in the GUI I don't know about?). If I'm on tab 255 and click on tab 256 gVim jumps to tab 254 instead of 256. With another click on tab 256 it instantly shows me tab 253, after another click on tab 256 it jumps back to tab 252 and so on.
When clicking on the last tab (257) gVim switches to the very first tab/buffer. If I open another tab Vim does it and navigating with gt and gT trough the additional tabs above tab 255 works fine but clicking on the new tab 258 opens tab 2. So I assume the tab counter of the GUI ends with 256. Is there a way to fix this?
(BTW: Sorry if my English is hard to understand. I'm not a native speaker of English.)
Congrats you found a bug. Read :h bugs and report it at vim_dev#vim.org. There is probably no way to fix it without recompiling vim.
Why do you have so many tabs? Do you really need tabs you probably could get by with just using the buffers. Read how to use buffers effectively.

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 - howto close all buffers in the current tab?

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.

Resources