I tend to open multiple tabs in vim and multiple windows within a tab.
I have a habit of traversing the code in a tree format - I open a tag in a new tab, so that my current view of the window remains unchanged. I can simply close the newly opened tab/window to resume to my previous view.
Consider a case where I have window A
focused. I open a new split as window B
. Now, when I close window B
, it should focus the earlier window A
. Currently, it always focuses the window on left side of B
.
Similarly, for tab close case, it always selects the tab on the right side of tab being closed.
Is there a way to keep track of the tab/window opening sequence in vim? Then I can trace back the sequence while closing the tab/windows...
Or better, is there a vim set
command option or an internal variable that handles this automatically?
WinLeave
andWinEnter
to maintain a stack of windows in the order you visit them. But maintaining the stack directly would be a pain in the rear, since (1) windows are per-tab, and (2) their IDs get re-allocated. You could get around that by creating your own unique IDs for each window, store them inw:
variables, and put those in the stack. It would probably work eventually, but it would still be as robust asautocmd
s. Probably a reasonable idea for a plugin, too.winnr()
& store that asw:winnr2
...