2

I've been using Vim for decades (and Vi before it since around 1984.) I use it now on Linux. Somewhere along the line one behavior crept in that I'd like to disable: when I click in a window to move the focus, and the click happens to be in the body of the window, Vim moves the cursor to wherever the click landed. If the window is large, it's sometimes not obvious where the cursor was, and that can be important for what I'm trying to do.

I know I could try to click on the window border somewhere, and this wouldn't happen. But I'd rather not have to be that meticulous, especially when there are a lot of windows around. I also know there are other ways to change focus, but I don't want to cycle through every window on my 3-monitor workspace.

I'm running Ubuntu and Xubuntu, and have loaded Vim-gtk because I sometimes want to run full graphical, where I could live with this behavior. But I'm usually not in graphical mode.

I see there's a Vim-tiny that probably does not have this behavior, but I don't know what else I would lose.

I've looked through the setup stuff for the window manager and don't see anything relevant. The Vim man page doesn't have anything that jumped out at me either. My .vimrc doesn't seem to address the issue (but it's long and I may have forgotten/missed something.)

Any suggestions?

  • You could try set mousefocus, but I don't think that's quite what you're looking for. – Tumbler41 Apr 18 '17 at 20:51
2

Here's a heavy solution:

nnoremap <LeftMouse> ma<LeftMouse>`a

It will let the click go through (thus changing the focus), but make sure the cursor always goes back to where it was before the click was initiated.

  • This seems to work for me, after I removed the initial 'n'; changing focus seems to leave me in whatever mode I was in, and I just don't want the mouse to move the cursor ever. But then I usually have my fingers pretty much glued to the keys -- I don't use the mouse much for anything except moving windows, changing focus, or when the window or display manager require the mouse. – 4dummies May 16 '17 at 16:19
0

From Vim Tips Wiki:

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

Although I am unable to test this on Linux, I've recently started using it on Windows, and it appears to do what you're asking for. (Note that somebody reported an issue with split windows, i.e. after :split, but I haven't observed it myself.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.