1

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

Neovim lua doc says:

                                                            vim.opt:append()
Option:append(value)

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

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

I have this line on init.lua:

vim.o.matchpairs:append("<:>")

But Neovim returns an error:

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

How can I solve this problem?

1
  • 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 :-) May 27 at 12:47

1 Answer 1

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 .. ","
end
vim.o.matchpairs = vim.o.matchpairs .. "<:>"

I suppose the confusion comes from o vs. opt.

You could also do:

vim.opt.matchpairs:append("<:>")
2
  • 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
    May 26 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. May 26 at 13:02

Your Answer

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

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