Set Vim plugin options in a NeoVim init.lua

Viewed 1712

I want to set vim plugin options that have the vimscript format let some#option = option inside my NeoVim init.lua file, but I can't figure out how to set these options in a format that NeoVim respects.

I've tried using vim.cmd("let some#option = option") but this doesn't seem to work. Any advice? Thanks!

1 Answers

From nanotee/nvim-lua-guide, the section on Managing vim internal variables shows various API calls, including

In practice, setting a global variable looks like

vim.api.nvim_set_var('some#var', 'value')

You can also use the meta-accessors, such as vim.g:

vim.g['some#var'] = 'value'

The method with vmd.cmd can work, although using the more structured API shown above is advised.

Note that in vim.cmd("let some#option = option") the right-hand side of the assignment operator is an expression. This means the plain token option would be evaluated as an identifier.

Depending on what you are trying to do, you may need add additional quotes to create a string.

vim.cmd("let some#var = 'value'")
Related