Skip to content

Commit 827a7f2

Browse files
committed
Add ability to use nerdfont.vim plugin to display devicons
1 parent 3ee5c83 commit 827a7f2

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ tabline works and looks like.
141141
| `g:buffet_separator` | `''` | The character to be used for separating items in the tabline |
142142
| `g:buffet_show_index` | `0` | Set to `1`, show index before each buffer name. Index is useful for switching between buffers quickly |
143143
| `g:buffet_max_plug` | `10` | The maximum number of `<Plug>BuffetSwitch` provided. Mapping will be disabled if the option is set to `0` |
144-
| `g:buffet_use_devicons` | `1` | If set to `1` and [`vim-devicons`](https://github.com/ryanoasis/vim-devicons) plugin is installed, show file type icons for each buffer in the tabline. If the `vim-devicons` plugin is not present, the option will automatically default to `0` (*Note: you need to have `vim-devicons` loaded before `vim-buffet` in order to make this work*) |
144+
| `g:buffet_use_devicons` | `1` | If set to `1` and either [`vim-devicons`](https://github.com/ryanoasis/vim-devicons) or [`nerdfont.vim`](https://github.com/lambdalisue/nerdfont.vim) plugin is installed, show file type icons for each buffer in the tabline. If neither plugin is present, the option will automatically default to `0`. |
145145
| `g:buffet_tab_icon` | `'#'` | The character to be used as an icon for the tab items in the tabline |
146146
| `g:buffet_new_buffer_name` | `'*'` | The character to be shown as the name of a new buffer |
147147
| `g:buffet_modified_icon` | `'+'` | The character to be shown by the name of a modified buffer |

autoload/buffet.vim

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ function! s:Render()
269269
let trunc_len = left_trunc_len + right_trunc_len
270270

271271
let capacity = &columns - tabs_len - trunc_len - 5
272-
let buffer_padding = 1 + (g:buffet_use_devicons ? 1+1 : 0) + 1 + sep_len
272+
273+
let devicon_func = buffet#get_devicon_func()
274+
let use_devicon = len(devicon_func) > 0
275+
276+
let buffer_padding = 1 + (use_devicon ? 1+1 : 0) + 1 + sep_len
273277

274278
let elements = s:GetAllElements(capacity, buffer_padding)
275279

@@ -293,8 +297,8 @@ function! s:Render()
293297
endif
294298

295299
let icon = ""
296-
if g:buffet_use_devicons && s:IsBufferElement(elem)
297-
let icon = " " . WebDevIconsGetFileTypeSymbol(elem.value)
300+
if use_devicon && s:IsBufferElement(elem)
301+
let icon = " " . call(devicon_func, [elem.value])
298302
elseif elem.type == "Tab"
299303
let icon = " " . g:buffet_tab_icon
300304
endif
@@ -430,3 +434,15 @@ function! buffet#bonly(bang, buffer)
430434
call buffet#bwipe(a:bang, b)
431435
endfor
432436
endfunction
437+
438+
function! buffet#get_devicon_func()
439+
if !get(g:, "buffet_use_devicons", 1)
440+
return ""
441+
elseif exists("*WebDevIconsGetFileTypeSymbol")
442+
return "WebDevIconsGetFileTypeSymbol"
443+
elseif exists("*nerdfont#find")
444+
return "nerdfont#find"
445+
else
446+
return ""
447+
endif
448+
endfunction

plugin/buffet.vim

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ let g:buffet_show_index = get(g:, "buffet_show_index", 0)
3131

3232
let g:buffet_max_plug = get(g:, "buffet_max_plug", 10)
3333

34-
if get(g:, "buffet_use_devicons", 1)
35-
if !exists("*WebDevIconsGetFileTypeSymbol")
36-
let g:buffet_use_devicons = 0
37-
else
38-
let g:buffet_use_devicons = 1
39-
endif
40-
else
41-
let g:buffet_use_devicons = 0
42-
endif
43-
4434
if !exists("g:buffet_modified_icon")
4535
let g:buffet_modified_icon = "+"
4636
endif

0 commit comments

Comments
 (0)