Wikia

Vim Tips Wiki

How to not move cursor when selecting window with mouse

Talk0
1,610pages on
this wiki
Revision as of 08:21, July 14, 2012 by JohnBot (Talk | contribs)

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 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)

Advertisement | Your ad here

Around Wikia's network

Random Wiki