How does set mouse+=a
translate to the equivalent Lua Neovim setting?
Asked
Active
Viewed 805 times
5

lovelikelando
- 7,593
- 6
- 32
- 50
-
2`mouse = mouse + a`? – Luke100000 Jun 12 '22 at 22:24
3 Answers
5
vim.opt.mouse
returns a mouse option object.
You can use Option:append(value)
to append a string value to an option like this.
-- These are equivalent
vim.opt.mouse:append('a')
vim.opt.mouse = vim.opt.mouse + 'a'
Learn more in :h vim.opt:append()
There is also a vim.o.mouse
, which returns the option as a string. You can also append a string value to it using ..
.
vim.o.mouse = vim.o.mouse .. 'a'

Jian
- 3,118
- 2
- 22
- 36
4
From the neovim docs: https://neovim.io/doc/user/lua.html#lua-vim-options
To replicate the behavior of |:set+=|, use:
-- vim.opt supports appending options via the "+" operator vim.opt.wildignore = vim.opt.wildignore + { "*.pyc", "node_modules" } -- or using the `:append(...)` method vim.opt.wildignore:append { "*.pyc", "node_modules" }
To replicate the behavior of |:set^=|, use:
-- vim.opt supports prepending options via the "^" operator vim.opt.wildignore = vim.opt.wildignore ^ { "new_first_value" } -- or using the `:prepend(...)` method vim.opt.wildignore:prepend { "new_first_value" }
To replicate the behavior of |:set-=|, use:
-- vim.opt supports removing options via the "-" operator vim.opt.wildignore = vim.opt.wildignore - { "node_modules" } -- or using the `:remove(...)` method vim.opt.wildignore:remove { "node_modules" }
-
Weirdly, `vim.o.` doesn't work with append, you have to use the more verbose `vim.opt.` – Jeff Irwin Apr 04 '23 at 00:46
1
In Lua, there is no +=
operator. The equivalent to
set mouse += a
in Lua would be:
mouse = mouse + a

rosemash
- 274
- 1
- 7