4

I run a Linux/GNOME laptop where the focus follows the mouse, and I have vim's mousefocus feature turned on, so the selected viewport follows the mouse, too. But when I try to switch viewports using Ctrl+W j or Ctrl+W k (AKA, in vim help, CTRL-W_j or CTRL-W_k), the active viewport stays as whichever one the mouse is over.

The thing is, this is a new problem. I have a .vimrc file that's evolved since the 1990s, through dozens of machines on multiple platforms, and I don't remember having to deal with this issue before. Unfortunately, I don't have my old laptop to compare it with, and for various reasons, I made do without my .vimrc file on my new laptop until today. But other than it being an updated laptop, running a newer version of Linux Mint (Cinnamon) and a newer version of vim, and loading (seemingly unrelated) extensions via a plug-in manager, it's essentially the same setup I've had for years. (I have set mouse=a, FWIW, which again is what it's been set to since before the turn of the century.)

I think what happened on my previous laptops is that the mouse followed the active viewport in vim, if I used Ctrl+W j or Ctrl+W k to change it. I've been looking for a plugin or setting to make it do that again, but I can't find it. So perhaps this behaviour has changed between version 7.3 and 8.0?

Any ideas how to fix this?

  • 1
    <C-w>n creates a new window, rather than move. That said, this sounds like the feature working "as intended" (i.e., the focus stays with the mouse pointer). Disabling 'mousefocus' is probably the best bet. Setting mouse=a will still alllow you to click if need be – D. Ben Knoble Jan 12 at 16:38
  • 1
    Thanks, but I actually found having mousefocus turned off one of the most frustrating things about the defaults. Nearly 30 years of X-windows/GNOME got me really used to just moving the mouse and typing, not needing the extra click, yet still being able to Alt+Tab between windows when the mouse was less convenient. Vim always worked the same way; when I changed viewports with Ctrl+W j/k, it either moved the mouse for me, or it ignored mousefocus until I moved the mouse again. I can't remember exactly, but it worked for me since I retired my Windows '98 laptop. – Michael Scheper Jan 12 at 23:22
  • And yes, I typed the wrong key combination—thanks. Looks like I'm not that good recalling key combinations from muscle memory. 🤨 I've fixed it now. – Michael Scheper Jan 12 at 23:29
  • I removed your suggestions about new tags, and added the vim-windows tag, as window is the standard Vim terminology for viewport. Having viewport as a tag synonym for vim-windows might be a good idea, but I suspect that mousefocus is a bit narrow for a new tag. Either way, I think asking a question on the meta site is probably a better place for such requests. (As in, it's more likely to elicit a response/results there). – Rich Jan 13 at 10:38
  • 1
    FWIW, This works how you'd like it to in my installation of v8.1 MacVim. However, it does not work as documented: :help mousef states: When changing the window layout or window focus in another way, the mouse pointer is moved to the window with keyboard focus but for me, when switching windows with the keyboard, the mouse pointer stays where it is. Possibly worth raising an issue on the Vim github repository about this issue? – Rich Jan 13 at 10:47

Your Answer

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

Browse other questions tagged or ask your own question.