Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get fileformat icon ? #51

Open
krisfans opened this issue Mar 31, 2021 · 8 comments
Open

How to get fileformat icon ? #51

krisfans opened this issue Mar 31, 2021 · 8 comments

Comments

@krisfans
Copy link

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

@kyazdani42
Copy link
Member

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

@krisfans
Copy link
Author

krisfans commented Apr 1, 2021

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

@kyazdani42
Copy link
Member

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

@sbromberger
Copy link

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!

@kyazdani42
Copy link
Member

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 ?

@atanasj
Copy link

atanasj commented Oct 18, 2021

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!

@brankojay
Copy link

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

@escasinas
Copy link

Do you have a patched font installed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants