I want to append <:> to vim.opt.matchpairs, which AFAIK is a string type.

Neovim lua doc says:


    Append a value to string-style options. See :set+=

    These are equivalent:
        vim.opt.formatoptions = vim.opt.formatoptions + 'j'

I have this line on init.lua:


But Neovim returns an error:

...attempt to call method 'append' (a nil value)...

How can I solve this problem?

  • Do you still have something open? How can we help you further? If the solution address your need maybe could you accept it using the v button next to the arrow voting buttons. It allow the question to rest :-) Commented May 27, 2023 at 12:47

1 Answer 1


My understanding is that vim.o.matchpairs is a string.

I would do:

vim.o.matchpairs = vim.o.matchpairs .. ",<:>"

or to take into account that `vim.o.matchpairs" could be empty

if not vim.o.matchpairs then
  vim.o.matchpairs = vim.o.matchpairs .. ","
vim.o.matchpairs = vim.o.matchpairs .. "<:>"

I suppose the confusion comes from o vs. opt.

You could also do:

  • 1
    Oh lord… vim.o and vim.opt are different but the same? That seems like it could cause no end of confusion. Interesting to learn that .. is also Lua's string concatenation operator, but + is the same as :append.
    – D. Ben Knoble
    Commented May 26, 2023 at 12:55
  • The o seems to be string versions of the opt versions. It allows to write Lua code that iterate over the opt version without having to split the o version into parts. Commented May 26, 2023 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.