英文:
nvim - deactivating mouse
问题
你能帮助我吗?我想在 nvim 中禁用鼠标。它既不应滚动,也不应更改光标位置。
我在我的 init.lua 中添加了以下行,以禁用鼠标滚动:
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
这有效果,滚动已被禁用。但是,我仍然可以通过点和点击来更改光标位置。为了禁用这一点,我还添加了以下行:
vim.opt.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?
答案1
得分: 2
我终于弄清楚了。
这种行为的原因是终端仿真器将触摸板上的滚动重新映射为箭头键。因此,如果我禁用鼠标,nvim 仍然会接收到箭头键信息。
因此,一个解决方法是取消映射箭头键并禁用鼠标:
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 = ""
英文:
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 = ""
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论