I find myself in this situation very often:
- Open gVim with NERDTree from current working directory.
- Open a file from NERDTree using
<S-T>
so it grabs a new tab. :tabprevious
to return to NERDTree.- Explore directories and open a second file using
<S-T>
. - Close the second file,
:q
orZZ
.
What I would have expected to happen after 5. is to return to NERDTree, but Vim always collapses the tab and opens the one to the right. This is rarely what I intended to do and would much rather have Vim keep a list of all tabs I have cycled through. So, as I close one, it pops it off the stack and focuses the next.
This can be seen in other editors, mostly IDEs, like Komodo Edit for example.
Is there a plug-in which would do this for Vim?
Best Answer
To go to the first tab (presumably the one with NERDTree open), do
:tabfirst
. Vim doesn't keep a list of tabs ordered by "most recently accessed" and:tabprevious
/:tabnext
only deal with the tabs on the left/right.The default action for
T
is precisely to open the selected file in a new tab and come back to the tab where NERDTree is located. So I'm not sure why you have to do:tabprevious
afterT
.A common way to use NERDTree is to simply open it on the spot, when you need it, and set it to close itself upon opening a file. I don't remember the name of the option but a quick
:help nerdtree
would be enough.Also I'm afraid you are making a mistake here: you are using Vim's "tabs" as if they where the same as the tabs found everywhere else. This is a bad idea because they are not designed that way at all. Instead, read up on windows and buffers.