nvim-tree.lua
nvim-tree.lua copied to clipboard
User Defined Icons and Highlight Groups
Is your feature request related to a problem? Please describe.
I think it would be really great if you could have custom folder icon colors & custom folder icons depending on the name of the folder. For example, all of my folders are grey, but I would love if I could make node_modules folders green, pages folders orange, dist folders a light red, you get the idea. I think being able to change the icons too would be a bonus.
Describe the solution you'd like
I think a few main highlight groups for popular folders would be great, such as NvimTreeNodeModulesFolder, NvimTreeUtilsFolder, NvimTreeLuaFolder, and NvimTreeStylesFolder, and maybe some more. What I think would be absolutely perfect would be being able to dynamically add them for whatever name the user wants by setting it up the config, something like
nvim_tree.setup({
folder_overrides = {
{ name: "lua", iconColor: "#000000", icon: " " }
}
})
Describe alternatives you've considered N/A
Additional context
In this picture you can see the node_modules folder is set to a green folder icon, and types has blue folder icon. This is what I think would be awesome as a feature.

name can be a vim.regex
Icon and name colour would be separate highlight groups.
A convention-over-configuration approach would be best, something like UserLua to match NvimTreeUserLuaFolder, NvimTreeUserLuaIcon and possibly NvimTreeUserLuaFile.
i want a implematation of this
what's about this: https://github.com/uiwjs/file-icons
file-icons looks to provide the same functionality as nvim-web-devicons which nvim-tree uses.
It doesn't appear to provide the per-directory colouring and isn't written in lua, so it's not something we could use.
On reflection, I don't think this is functionality that nvim-tree should provide; nvim-web-devicons should provide this functionality.
Please raise a feature request at https://github.com/nvim-tree/nvim-web-devicons with a proposed override_ setup option pattern.
On reflection, I don't think this is functionality that
nvim-treeshould provide;nvim-web-deviconsshould provide this functionality.Please raise a feature request at https://github.com/nvim-tree/nvim-web-devicons with a proposed
override_setup option pattern.
https://github.com/nvim-tree/nvim-web-devicons/issues/105
we don't manage folders in this repository unfortunately. This would depend on the plugin you are using.
+1 would be a nice feat to have
In terms of nvim-web-devicons it is now possible to override icons at runtime and setup time.
Following #2415 this is more of a possibility for nvim-tree only:
- highlighting is additive and could be applied in the usual precedence: base < USER < git < opened < modified < bookmarked < diagnostics < copied < cut
- A new
Decoratorcould be added to handle user icons / highlights
User configuration needed:
- icon glyphs, may be from nvim-web-devicons
- highlight groups to cover both HL and icons
- mechanism to match files/folders to the above
Rather than complex configuration, a simple function is preferable. Something like:
---User defined highlighting and icon
---@param node Node cutdown
---@return string|nil node_hl highlight group for the node name
---@return string|nil icon_glyph glyph to replace the node's icon
---@return string|nil icon_hl highlight group for the icon
local function(node)
---