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
    Jul 11 '21 at 0:10
  • The example shows how to set listchars: vim.opt.listchars = { space = '_', tab = '>~' } but not how to append to the default.
    – n8henrie
    Jul 12 '21 at 3:21

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
    Sep 28 '21 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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