This is an automated archive made by the Lemmit Bot.

The original was posted on /r/neovim by /u/lostAnarchist1984 on 2025-06-11 10:44:19+00:00.


I used to use indent-blankline for some time but I found out that the listchars options was good enough for me (the string for tab and leadmultispace is U+258F followed by a space).

vim.opt.listchars = {
  tab = "▏ ",
  extends = "»",
  precedes = "«",
  leadmultispace = "▏ "
}

The downside of using listchars is that empty lines will break the indent guide. Again, this is not a huge deal for me.

However, I didn’t like that in programming languages where the indent size != 2, this would display the wrong number of indent guides, which looks really bad. Today I decided to try and fix it and I came up with this:

-- Set listchars
vim.api.nvim_create_autocmd("BufWinEnter", {
  callback = function()
    sw = vim.fn.shiftwidth()
    vim.opt.listchars = vim.tbl_deep_extend(
      "force",
      vim.opt_local.listchars:get(),
      {
        tab = '▏' .. (' '):rep(sw - 1),
        leadmultispace = '▏' .. (' '):rep(sw - 1)
      }
    )
  end
})

You may have to change the event BufWinEnter depending on when your shiftwidth gets set in your config. For me this happens with my .editorconfig file, so quite late. I’m quite satisfied with this. Let me know if you find this useful or can think of a way to improve the code.