Search code examples
linuxneovim

nvim - deactivating mouse


can you help me? I Want to deactivate the mouse in nvim. It should neither scroll, nor change the cursor position.

I added the following lines to my init.lua, to disable scrolling by mouse:

for _, amplitude in ipairs({ "", "S-", "C" }) do
    for _, direction in ipairs({ "Up", "Down", "Left", "Right" }) do
    for _, modus in ipairs({ "", "i" }) do
        vim.keymap.set(modus, "<" .. amplitude .. "ScrollWheel" .. direction .. ">", "<Nop>", { })
    end
    end
end

This works, and scrolling is disabled. However, I can still change the curser position by point and click. To disable this, I also added the following line:

vim.opt.mouse = ""

Now, I can't change the curser by point and click, but scrolling is active again. I don't understand why? Is there a way to deactivate both?


Solution

  • I finally figured it out.

    The reason for this behavior is that scrolling on touchpads is remaped to the arrow keys by the terminal emulator. Hence, if I disable mouse nvim still gets the arrow key information.

    Conequently a solution was to nomap the arrow keys and disable mouse:

    vim.keymap.set("", "<up>", "<nop>", { noremap = true })
    vim.keymap.set("", "<down>", "<nop>", { noremap = true })
    vim.keymap.set("i", "<up>", "<nop>", { noremap = true })
    vim.keymap.set("i", "<down>", "<nop>", { noremap = true })
    
    vim.opt.mouse = ""