In a neovim init.lua config, I know that I can append to a string like so:


However, I'm getting errors with the following attempts to append extends:# to the default value of listchars:

vim.opt.listchars = vim.opt.listchars + "extends:#"
vim.opt.listchars = vim.opt.listchars + ",extends:#"

I thought it was perhaps because it's a mapping, but this also failed:

vim.opt.listchars:append({extends = "#"})

EDIT: ^^ this now works on 0.5.1. See below.

I don't see an :extend() method, but tried it anyway and it also fails.

It accepts this as valid: vim.opt.listchars = "extends:#"

What am I doing wrong here?

  • 1
    There’s an example in help lua-vim-setlocal (search for listchars), at least in the version I checked online. I think you need to use a table.
    – D. Ben Knoble
    Commented Jul 11, 2021 at 0:10
  • The example shows how to set listchars: vim.opt.listchars = { space = '_', tab = '>~' } but not how to append to the default.
    – n8henrie
    Commented Jul 12, 2021 at 3:21

4 Answers 4


The 'listchars' option is implemented as a Lua table (akin to a Dict in Vim, possibly more similar to an object in JavaScript), so what you need to only change the extends setting is:

vim.opt.listchars.extends = "#"

Or, also valid:

vim.opt.listchars["extends"] = "#"
  • 1
    Unfortunately this is no longer working, neovim 0.5.1 MacOS or Arch Linux.
    – n8henrie
    Commented Sep 28, 2021 at 15:05

As of nvim 0.5.1, on MacOS and Linux, it appears that the vim.opt.listchars:append in my original question now works, and for some reason setting the map values as in vim.opt.listchars.extends = "e" or vim.opt.listchars.tab = "t" no longer works.

vim.opt.listchars:append({ extends = "#" })

Actual this works (from the official doc: https://neovim.io/doc/user/lua.html): vim.opt.listchars = { space = '_', tab = '>~' }

In my case I got to add (init.lua or outsourced file for global-lua-settings)

vim.opt.listchars = {eol = '↵'}   
vim.opt.list = true
  • Thanks for your input, but the question was specifically about extending the existing value, not overwriting it; I also mentioned your example in my comment: vi.stackexchange.com/questions/31811/…
    – n8henrie
    Commented Jan 20, 2022 at 15:14

You can use:
vim.opt.listchars:append({ eol = '↵' })
or vim.opt.listchars + { eol = '↵' } to append
and vim.opt.listchars:prepend({ eol = '↵' })
or vim.opt.listchars ^ { eol = '↵' } to prepend to nvim Option objects.

Source: https://neovim.io/doc/user/lua.html#vim.env

  • I had to add vim.opt.list = true to make the config work Commented Nov 14, 2022 at 19:44

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.