1

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

vim.opt.wildignore:append("*/node_modules/*,*/vendor/*,*/venv/*,*/.venv/*,*/target/*")

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

vim.opt.listchars:append("extends:#")
vim.opt.listchars:append(",extends:#")
vim.opt.listchars:append({"extends:#"})
vim.opt.listchars:append({",extends:#"})
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?

2
  • 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 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 at 3:21
2

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
  • 1
    Unfortunately this is no longer working, neovim 0.5.1 MacOS or Arch Linux.
    – n8henrie
    Sep 28 at 15:05
1

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 = "#" })
print(vim.inspect(vim.opt.listchars:get()))

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.