0

Is it possible to get focus-follows-mouse behavior in terminal Neovim?

Please note this is different from this question about how to focus a window by clicking the mouse. This question is about how to focus a window by moving the mouse.

By focus-follows-mouse, I mean when the mouse pointer is hovered over a window that is not activated, it should be activated as if I switched to it using e.g. <C-w><Up>.

I found the mousefocus option which sounds like exactly what I want:

'mousefocus' 'mousef'   boolean (default off)
            global
    The window that the mouse pointer is on is automatically activated.
    When changing the window layout or window focus in another way, the
    mouse pointer is moved to the window with keyboard focus.  Off is the
    default because it makes using the pull down menus a little goofy, as
    a pointer transit may activate a window unintentionally.

Unfortunately, adding set mouse=a mousefocus to my configuration has no effect. Moving the mouse pointer over an unfocused window doesn't do anything. (Having the mouse pointer automatically moved when I do <C-w><Up> sounds annoying, but that's not happening either.) I tried this in Kitty and Gnome Terminal.

3
  • Welcome to Vim! In my tests it only works on gVim. Commented Mar 22, 2023 at 18:03
  • 1
    Voting to close this question as LeftMouse focus window without moving cursor has better answers.
    – Friedrich
    Commented May 31, 2023 at 7:26
  • Lol, I guess this happens pretty often on stack exchange but the question you've marked this as duplicating is totally unrelated. Would you mind reopening please?
    – Alex Burka
    Commented Jul 7, 2023 at 15:45

1 Answer 1

0

The Vim 9.0 documentation says: only works in the GUI

'mousefocus' 'mousef'   boolean (default off)
            global
            {only works in the GUI}
    The window that the mouse pointer is on is automatically activated.
    When changing the window layout or window focus in another way, the
    mouse pointer is moved to the window with keyboard focus.  Off is the
    default because it makes using the pull down menus a little goofy, as
    a pointer transit may activate a window unintentionally.
    MS-Windows: Also see 'scrollfocus' for what window is scrolled when
    using the mouse scroll wheel.

Where: "only works on the GUI" means only on gVim (and potentially on nvim-qt but in my experience it does not).

The possibility for nvim-qt to implemented mousefocusis only available since 6th of September 2020 (see issue 12849 but has not been implemented so far.

4
  • Hmm, OK thanks. I know that mouse hover events are possible, somehow, so maybe we can implement similar functionality in a plugin.
    – Alex Burka
    Commented Mar 22, 2023 at 18:20
  • 1
    Should there be an issue open on Neovim to further document this option, or remove it since it doesn't work? According to this github comment it may be implemented in the backend but not in the UI.
    – Alex Burka
    Commented Mar 22, 2023 at 18:21
  • My understanding is that the backend inform the GUI but the nvim-qt GUI didn't took care so far. You could introduce a demand to nvim-qt. Commented Mar 22, 2023 at 18:23
  • 1
    Based on what bufferline.nvim is doing, maybe the route to getting this working in the terminal is to use mousemoveevent instead of mousefocus.
    – Alex Burka
    Commented Mar 22, 2023 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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