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
au FocusGained * normal <C-o>
<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`
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
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.