sponsor Vim development Vim logo Vim Book Ad

FocusPrevious : Focus previous window/tab when closing the current one.

 script karma  Rating 14/5, Downloaded by 815  Comments, bugs, improvements  Vim wiki

created by
Anish Sane
script type
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.

With this plugin, it maintains the order in which the tabs are switched and
the order in which windows are switched within a tab.
NOTE that the order of window switching is maintained in per-tab basis.

When any window/tab is closed, it focuses the tab that was last focussed.

Please provide feedback here: http://vi.stackexchange.com/a/9288/2749 (My question which led me into writing this script.)
install details
Actual script needs to be copied to ~/.vim/plugin.

This package us a VIMBall.

Download the script as FocusPrevious.vmb using wget/curl

On terminal:
$ wget http://www.vim.org/scripts/download_script.php?src_id=24462 -O FocusPrevious.vmb # The download URL would vary with new version
$ vim FocusPrevious.vmb

Inside vim:
: source %
: quit

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
FocusPrevious.vmb 1.0 2016-08-22 7.0 Anish Sane Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.