How does set mouse+=a translate to the equivalent Lua Neovim setting?
How does set mouse+=a translate to the equivalent Lua Neovim setting?
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'
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" }
In Lua, there is no += operator. The equivalent to
set mouse += a
in Lua would be:
mouse = mouse + a