diff --git a/README.md b/README.md index 099b606f..633e3991 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ You can override the default icon with the `set_default_icon(icon, color, cterm_ require("nvim-web-devicons").set_default_icon('', '#6d8086', 65) ``` -### Getting icons by filetype +### Getting and setting icons by filetype You can get the icon and colors associated with a filetype using the `by_filetype` functions: @@ -177,6 +177,12 @@ require("nvim-web-devicons").get_icon_color_by_filetype(filetype, opts) require("nvim-web-devicons").get_icon_cterm_color_by_filetype(filetype, opts) ``` +or set the icon to use for a filetype with: + +```lua +require("nvim-web-devicons").set_icon_by_filetype { cpp = "c", pandoc = "md", } +``` + These functions are the same as their counterparts without the `_by_filetype` suffix, but they take a filetype instead of a name/extension. You can also use `get_icon_name_by_filetype(filetype)` to get the icon name associated with the filetype. diff --git a/lua/nvim-web-devicons.lua b/lua/nvim-web-devicons.lua index 4301079a..a4a927a4 100644 --- a/lua/nvim-web-devicons.lua +++ b/lua/nvim-web-devicons.lua @@ -510,6 +510,10 @@ function M.set_icon(user_icons) end end +function M.set_icon_by_filetype(user_filetypes) + filetypes = vim.tbl_extend("force", filetypes, user_filetypes or {}) +end + function M.set_default_icon(icon, color, cterm_color) default_icon.icon = icon default_icon.color = color