nvim-web-devicons icon indicating copy to clipboard operation
nvim-web-devicons copied to clipboard

How to get fileformat icon ?

Open krisfans opened this issue 3 years ago • 8 comments

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. Snipaste_2021-03-31_23-28-35

krisfans avatar Mar 31 '21 15:03 krisfans

Hi, i'm not sure what you mean by that, did you read the README ?

kyazdani42 avatar Mar 31 '21 19:03 kyazdani42

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

krisfans avatar Apr 01 '21 14:04 krisfans

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

kyazdani42 avatar Apr 01 '21 17:04 kyazdani42

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!

sbromberger avatar Jun 06 '21 21:06 sbromberger

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 ?

kyazdani42 avatar Jun 07 '21 15:06 kyazdani42

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!

atanasj avatar Oct 18 '21 15:10 atanasj

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'
    }
}

brankojay avatar May 04 '22 08:05 brankojay

Do you have a patched font installed?

escasinas avatar Oct 17 '22 11:10 escasinas