Skip to content

Commit 69fb193

Browse files
authored
feat(#406): add set_icon_by_filetype (#407)
simply adds/updates user-defined filetypes to the internal filetypes table. fixes #406
1 parent 0bb67ef commit 69fb193

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ You can override the default icon with the `set_default_icon(icon, color, cterm_
166166
require("nvim-web-devicons").set_default_icon('', '#6d8086', 65)
167167
```
168168

169-
### Getting icons by filetype
169+
### Getting and setting icons by filetype
170170

171171
You can get the icon and colors associated with a filetype using the `by_filetype` functions:
172172

@@ -177,6 +177,12 @@ require("nvim-web-devicons").get_icon_color_by_filetype(filetype, opts)
177177
require("nvim-web-devicons").get_icon_cterm_color_by_filetype(filetype, opts)
178178
```
179179

180+
or set the icon to use for a filetype with:
181+
182+
```lua
183+
require("nvim-web-devicons").set_icon_by_filetype { cpp = "c", pandoc = "md", }
184+
```
185+
180186
These functions are the same as their counterparts without the `_by_filetype` suffix, but they take a filetype instead of a name/extension.
181187

182188
You can also use `get_icon_name_by_filetype(filetype)` to get the icon name associated with the filetype.

lua/nvim-web-devicons.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@ function M.set_icon(user_icons)
510510
end
511511
end
512512

513+
function M.set_icon_by_filetype(user_filetypes)
514+
filetypes = vim.tbl_extend("force", filetypes, user_filetypes or {})
515+
end
516+
513517
function M.set_default_icon(icon, color, cterm_color)
514518
default_icon.icon = icon
515519
default_icon.color = color

0 commit comments

Comments
 (0)