nvim-web-devicons
nvim-web-devicons copied to clipboard
How to get fileformat icon ?
Hi, Thank you for your work. I use lightline and vim-devicons to get icon in statusline. I want to know how to use nvim-web-devicons to get file icon and fileformat icon ,just look like this figure? I notice that nvim-web-devicons doesn't seem to provide such a approach.
Hi, i'm not sure what you mean by that, did you read the README ?
Where file format I mean the newline character- CR
and LF
, which has a different form in DOS, UNIX, and Mac, and in vimrc
,I cat set like this set fileformats=unix,dos,mac
i get what fileformats are, but i'm not sure about how it relates to getting an icon ? the icon returned is just a string
Sorry for resurrecting this, but I'm running into what may be the same question: is there an equivalent to vim-devicons WebDevIconsGetFileTypeSymbol()
and WebDevIconsGetFileFormatSymbol()
functions?
Thanks!
Hello, there is not getFileFormatSymbol function actually but there could be one (now i understand what this issue means). get file type symbol is the main function this plugins provides through require'nvim-web-devicons'.get_icon(filename, extension, { default = true })
to get the file format it would be quite easy to do, maybe just make a PR ?
I'm keen for this too as I would like to get rid of the vim-devicons
dependency for lightline
, but would not know where to start!
For anyone who comes across this - here's how i got the nvim-web-devicons
working with lightline
:
In Lua, define a function to provide the icon by filetype with get_icon_by_filetype
:
function getfiletypeicon( filetype )
local icon = require('nvim-web-devicons').get_icon_by_filetype( filetype )
return icon
end
The component_function
from lightline
expects a vimscript function (in my case, defined directly in Lua):
vim.cmd([[
function! CustomFilename()
let filetype = winwidth(0) > 70 ? (&filetype !=# '' ? &filetype : '-') : ''
let filename = expand('%:t') !=# '' ? expand('%:t') : '[no name]'
let filetypeicon = v:lua.getfiletypeicon(filetype)
return filetypeicon . ' ' . filename
endfunction
]])
Use CustomFilename
in your lightline
setup:
vim.g['lightline'] = {
active = {
left = {{'mode', 'paste'}, {'gitbranch', 'readonly', 'filename', 'modified'}}
},
component_function = {
filename = 'CustomFilename',
gitbranch = 'FugitiveHead'
}
}
Do you have a patched font installed?