I tend to use GVim a lot. Very frequently, I'll click on some other window and then when I click on vim to regain focus, my cursor will end up in some random location depending on where I clicked. I find this extremely obnoxious. I can generally remember where my cursor is before navigating away, but I don't like having to hunt it down every time I return to using gvim.
I thought I could fix this by adding this to my .vimrc
:
au FocusGained * normal <C-o>
(where <C-o>
is the actual control character) but this doesn't work. It usually just navigates away from my current file. This happens even if I add
au FocusLost * normal m`
too.
So I gave up on fixing this through the use of the jumplist. Instead, it seems like I could fix this by setting mouse
. In general, I'd prefer to have
set mouse=a
I initially tried the following autocommands:
au FocusLost * set mouse=
au FocusGained * set mouse=a
But it seems like the autocommand is processed before the mouse click is registered and the cursor is moved.
My next thought is to asynchronously re-enable the mouse so that the mouse click will be ignored before my mouse
setting is changed. Something along the lines of:
au FocusGained * async_call("set mouse=a", 200ms) "pseudocode
But I'm not sure exactly how to do this step. I can't find any info on the correct way to asynchronously call vimscript. I would like an answer either for how to do this asynchronously like I explained, but if there's a simpler way too achieve this then that would be appreciated too.
Any help would be appreciated. I am using vim 8.0 GUI version on Windows.
au FocusLost * set mouse=
technique works for me on GUI Vim 7.4 on Windows (10). I wonder if this is a bug introduced in Vim 8? Alternatively, perhaps a plugin you're using is mucking with something?au FocusLost * set mouse=
to disable it, and thenau FocusGained * set mouse=a
to reenable it? I'd like to havemouse=a
in general, otherwise I could just domouse=
so that I don't need to bother with autocommands.gvim -u NONE
and clicking in the window still moves the cursor. Which OS are you running?