Our code indentation generally consists of spaces or tabs. Therefore, we can customize the blank spaces, such as adding special characters to indicate a space, or adding background colors to achieve rainbow effects. Essentially, this mod inherits from indent and only rewrites the render method.
Since it inherits from indent, their configurations are almost similar and universal. The default configuration of the blank mod is as follows:
local default_conf = {
priority = 9,
chars = { "․" },
}
chars
is a Lua table whose characters are used to indicate how to render blank characters. You can set it like this to use the characters cyclically (although this setting does not look very good):
chars = {
" ",
"․",
"⁚",
"⁖",
"⁘",
"⁙",
},
style
inherits from indent, so the color is actually the same as indent and the configuration method is the same. See indent for details.
Here is the default blank style:
blank = {
chars = {
"․",
},
style = {
{ vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID("Whitespace")), "fg", "gui"), "" },
},
},
You can also set the spaces to be like a rainbow 🌈
blank = {
enable = true,
chars = {
" ",
},
style = {
{ bg = "#434437" },
{ bg = "#2f4440" },
{ bg = "#433054" },
{ bg = "#284251" },
},
},
indent = {
chars = {
"․",
},
style = {
{ vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID("Whitespace")), "fg", "gui"), "" },
"#806d9c",
"#c06f98",
},
}
You can also set multiple character types.
indent = {
chars = {
"․",
"⁚",
"⁖",
"⁘",
"⁙",
},
style = {
"#666666",
"#555555",
"#444444",
},
}
Finally, it can also set background colors.
blank = {
enable = true,
chars = {
" ",
},
style = {
{ bg = vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID("cursorline")), "bg", "gui") },
{ bg = "", fg = "" },
},
}