How to not move cursor when selecting window with mouse
Talk0this wiki
Recently created tip
We have not yet decided whether to keep this tip as its own page or merge it somewhere else. If you have a suggestion on the tip content, please edit this page or add your comments below (do not use the discussion page).
When you select the gvim window by using the mouse and clicking inside the window, it not only selects the window and brings it to the top, but it also moves the cursor to that location. If you don't want the cursor to move, put the following in your vimrc:
augroup NO_CURSOR_MOVE_ON_FOCUS au! au FocusLost * let g:oldmouse=&mouse | set mouse= au FocusGained * if exists('g:oldmouse') | let &mouse=g:oldmouse | unlet g:oldmouse | endif augroup END
Alternatively, if you are on a system which allows this, simply clicking on the GUI window chrome instead of the buffer text should give Vim focus without changing the cursor position.
Comments
Nice (although I haven't tested it). This should handle the OP problem, but with split windows, the same issue occurs: After :split, clicking in a window selects that window and moves the cursor to the position of the click. Perhaps some horrible kludge with WinLeave/WinEnter could be used (save/restore cursor?), although that seems unnecessary or even undesirable. We can simply make it clear exactly what the tip does with another sentence or two. JohnBeckett 07:53, January 4, 2012 (UTC)