5

How does set mouse+=a translate to the equivalent Lua Neovim setting?

lovelikelando
  • 7,593
  • 6
  • 32
  • 50

3 Answers3

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" }
ZenVentzi
  • 3,945
  • 3
  • 33
  • 48
JeremyKun
  • 2,987
  • 2
  • 24
  • 44
1

In Lua, there is no += operator. The equivalent to

set mouse += a

in Lua would be:

mouse = mouse + a
rosemash
  • 274
  • 1
  • 7