Vim Tips Wiki
Register
Advertisement

Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).

Please use new tips to discuss whether this page should be a permanent tip, or whether it should be merged to an existing tip.
created December 31, 2011 · complexity basic · version 7.0

When you are using another application and select go back to Vim by clicking inside Vim's text area, it not only switches application focus to Vim, 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)

Advertisement