Wikia

Vim Tips Wiki

How to not move cursor when selecting window with mouse

Talk0
1,613pages on
this wiki
Revision as of 05:16, October 10, 2012 by Fritzophrenic (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.

CommentsEdit

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)

Around Wikia's network

Random Wiki