nvim – 鼠标停用

huangapple go评论56阅读模式
英文:

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({ &quot;&quot;, &quot;S-&quot;, &quot;C&quot; }) do
    for _, direction in ipairs({ &quot;Up&quot;, &quot;Down&quot;, &quot;Left&quot;, &quot;Right&quot; }) do
	for _, modus in ipairs({ &quot;&quot;, &quot;i&quot; }) do
	    vim.keymap.set(modus, &quot;&lt;&quot; .. amplitude .. &quot;ScrollWheel&quot; .. direction .. &quot;&gt;&quot;, &quot;&lt;Nop&gt;&quot;, { })
	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 = &quot;&quot;

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(&quot;&quot;, &quot;&lt;up&gt;&quot;, &quot;&lt;nop&gt;&quot;, { noremap = true })
vim.keymap.set(&quot;&quot;, &quot;&lt;down&gt;&quot;, &quot;&lt;nop&gt;&quot;, { noremap = true })
vim.keymap.set(&quot;i&quot;, &quot;&lt;up&gt;&quot;, &quot;&lt;nop&gt;&quot;, { noremap = true })
vim.keymap.set(&quot;i&quot;, &quot;&lt;down&gt;&quot;, &quot;&lt;nop&gt;&quot;, { noremap = true })

vim.opt.mouse = &quot;&quot;

huangapple
  • 本文由 发表于 2023年2月19日 16:17:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75498817.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定