diff options
author | Teddy Wing | 2018-03-25 15:59:44 +0200 |
---|---|---|
committer | Teddy Wing | 2018-03-25 16:13:09 +0200 |
commit | 019805f339a0774574d97f138ea2b2c9425db0b4 (patch) | |
tree | c1a06a4545b1cdb20cce875012ec30555cdc9070 /vimrc | |
parent | f8efc45d741883eb1566b9973fe1a24a79061b97 (diff) | |
download | dotvim-019805f339a0774574d97f138ea2b2c9425db0b4.tar.bz2 |
git-blamer: Refocus original window when blamer buffer is closed
Previously, when the GitBlamer window was closed, the window it was
opened from would not be re-focused. Because of this, you couldn't just
pick up where you left off, you had to run a window command first.
This change re-focuses the original window automatically, bringing you
right where you were before opening GitBlamer.
Unfortunately, this seemingly simple want is not easy to do in VimL.
There's a `WinLeave` autocmd, but that event gets executed _before_
leaving a window. Similarly, the `BufWinLeave` autocmd we already had
gets executed before the buffer is removed from the window. Because
these events happen before the window is left, running the `wincmd w`
command doesn't work. We need a way to run the command after the window
is closed, allowing us to work with the new window layout and window
numbers.
In order to run `wincmd w` at the proper time, we add a new autocmd upon
closing the GitBlamer window that gets executed when any window is
entered. That autocmd refocuses the correct window and removes itself,
having served its purpose.
I used a tab variable to store the window number because it was a way to
allow multiple GitBlamer instances in different tabs. Otherwise, the
autocmd would be attached to a window that isn't correct in other tabs.
Also, augroups can't have dynamic names, so we can't create them
programmatically, preventing us from having multiple autocmds with
different window numbers for different tabs. The disadvantage of using a
tab variable is that window focus restoration doesn't work when multiple
GitBlamers are opened in a single tab.
Diffstat (limited to 'vimrc')
0 files changed, 0 insertions, 0 deletions