Git Product home page Git Product logo

nvim-web-devicons's Introduction

Notice

Nerd fonts moved some symbols with version 3.0. Version 2.3 is meant for transition, supporting both version 2 and version 3 icons.

Nvim-web-devicons requires version 2.3 or above to work properly. If you are unable to update please use your plugin manager to pin version of nvim-web-dev icons to nerd-v2-compat tag.

Nvim-web-devicons

A lua fork of vim-devicons. This plugin provides the same icons as well as colors for each icon.

Light and dark color variants are provided.

Requirements

Installation

Plug 'nvim-tree/nvim-web-devicons'

or with packer.nvim

use 'nvim-tree/nvim-web-devicons'

LuaRocks

Usage

Viewing

Run :NvimWebDeviconsHiTest to see all icons and their highlighting.

Variants

Light or dark color variants of the icons depend on &background.

The variant is updated:

  • on OptionSet event for background, or
  • after explicitly calling require("nvim-web-devicons").refresh().

However, be advised that the plugin using nvim-web-devicons may have cached the icons.

Setup

This adds all the highlight groups for the devicons i.e. it calls vim.api.nvim_set_hl for all icons this might need to be re-called in a Colorscheme to re-apply cleared highlights if the color scheme changes

require'nvim-web-devicons'.setup {
 -- your personnal icons can go here (to override)
 -- you can specify color or cterm_color instead of specifying both of them
 -- DevIcon will be appended to `name`
 override = {
  zsh = {
    icon = "",
    color = "#428850",
    cterm_color = "65",
    name = "Zsh"
  }
 };
 -- globally enable different highlight colors per icon (default to true)
 -- if set to false all icons will have the default icon's color
 color_icons = true;
 -- globally enable default icons (default to false)
 -- will get overriden by `get_icons` option
 default = true;
 -- globally enable "strict" selection of icons - icon will be looked up in
 -- different tables, first by filename, and if not found by extension; this
 -- prevents cases when file doesn't have any extension but still gets some icon
 -- because its name happened to match some extension (default to false)
 strict = true;
 -- same as `override` but specifically for overrides by filename
 -- takes effect when `strict` is true
 override_by_filename = {
  [".gitignore"] = {
    icon = "",
    color = "#f1502f",
    name = "Gitignore"
  }
 };
 -- same as `override` but specifically for overrides by extension
 -- takes effect when `strict` is true
 override_by_extension = {
  ["log"] = {
    icon = "",
    color = "#81e043",
    name = "Log"
  }
 };
 -- same as `override` but specifically for operating system
 -- takes effect when `strict` is true
 override_by_operating_system = {
  ["apple"] = {
    icon = "",
    color = "#A2AAAD",
    cterm_color = "248",
    name = "Apple",
  },
 };
}

Get Icon

Get the icon for a given file by passing in the name, the extension and an optional options table. The name is passed in to check for an exact match e.g. .bashrc if there is no exact name match the extension is used. Calls .setup() if it hasn't already ran.

require'nvim-web-devicons'.get_icon(filename, extension, options)

The optional options argument can used to change how the plugin works the keys include default = <boolean> and strict = <boolean>. If the default key is set to true this function will return a default if there is no matching icon. If the strict key is set to true this function will lookup icon specifically by filename, and if not found then specifically by extension, and fallback to default icon if default key is set to true. e.g.

require'nvim-web-devicons'.get_icon(filename, extension, { default = true })

You can check if the setup function was already called with:

require'nvim-web-devicons'.has_loaded()

Get icon and color code

get_icon_color differs from get_icon only in the second return value. get_icon_cterm_color returns cterm color instead of gui color get_icon returns icon and highlight name. If you want to get color code, you can use this function.

local icon, color = require'nvim-web-devicons'.get_icon_color("init.lua", "lua")
assert(icon == "")
assert(color == "#51a0cf")

Get all icons

It is possible to get all of the registered icons with the get_icons() function:

require'nvim-web-devicons'.get_icons()

This can be useful for debugging purposes or for creating custom highlights for each icon.

Mapped categories can be fetched via:

require'nvim-web-devicons'.get_icons_by_filename()
require'nvim-web-devicons'.get_icons_by_extension()
require'nvim-web-devicons'.get_icons_by_operating_system()
require'nvim-web-devicons'.get_icons_by_desktop_environment()
require'nvim-web-devicons'.get_icons_by_window_manager()

Set an icon

You can override individual icons with the set_icon({...}) function:

require("nvim-web-devicons").set_icon {
  zsh = {
    icon = "",
    color = "#428850",
    cterm_color = "65",
    name = "Zsh"
  }
}

You can override the default icon with the set_default_icon(icon, color, cterm_color) function:

require("nvim-web-devicons").set_default_icon('', '#6d8086', 65)

Getting and setting icons by filetype

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

require("nvim-web-devicons").get_icon_by_filetype(filetype, opts)
require("nvim-web-devicons").get_icon_colors_by_filetype(filetype, opts)
require("nvim-web-devicons").get_icon_color_by_filetype(filetype, opts)
require("nvim-web-devicons").get_icon_cterm_color_by_filetype(filetype, opts)

or set the icon to use for a filetype with:

require("nvim-web-devicons").set_icon_by_filetype { cpp = "c", pandoc = "md", }

These functions are the same as their counterparts without the _by_filetype suffix, but they take a filetype instead of a name/extension.

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

Known Issues

Windows and WSL not rendering icons properly on some terminals

On Windows and WSL, it is possible that the icons are not rendered properly when using a terminal that relies on Windows' default system libraries. An example of this is Alacritty (#271). Other terminals (e.g. Windows Terminal, and WezTerm) do no have this issue, as they ship newer versions of these libraries. More precisely, they use newer versions of conpty.dll and OpenConsole.exe. So, as a workaround to the rendering issue, you need to make your terminal use these newer files. Whether this is possible depends on the terminal you are using. Please refer to the terminal's documentation for this.

In the specific case of Alacritty, you need to place up-to-date conpty.dll and OpenConsole.exe files in your PATH. Microsoft does not provide these files directly, but you can get them from other terminal emulators that ship them.

Contributing

PRs are always welcome! Please see CONTRIBUTING

nvim-web-devicons's People

Contributors

adrian5 avatar akinsho avatar akmadan23 avatar alex-courtis avatar alexandrosalexiou avatar chmln avatar chrisgrieser avatar elianiva avatar gegoune avatar github-actions[bot] avatar hasecilu avatar kevinhwang91 avatar kyazdani42 avatar mcauley-penney avatar mg979 avatar nobuhikosawai avatar ofseed avatar ribru17 avatar romgrk avatar ronitkrshah avatar shatur avatar softinio avatar steschwa avatar superhawk610 avatar t-727 avatar theblckbird avatar uga-rosa avatar vinibispo avatar wesleimp avatar yorik1984 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nvim-web-devicons's Issues

Change all icon colors

Is it possible to change the colors of all icons somehow (without going through them one by one)?

Update svelte icon

Hello, thank you for writing this Plugin!
For some reason, the default icon displayed for .svelte is a lying red glyph, that has very little to do with the logo of the language. I tried looking into this myself but I can't seem to get this to work, so perhaps you could update the icon in general?
I saw an Issue for an icon for "teal" so I thought perhaps you could help with this.
The correct icon for svelte would be:
This one, which was recently merged into devicons.
Thank you!

Auto-setup

Have you thought about running .setup() automatically? What would you recommend for a plugin that depends on this? Do you have any reasons not to run .setup() automatically? If I may argue, anyone that has the plugin in their config is very highly to want .setup() to be called.

Reference: romgrk/barbar.nvim#11

Question: is intended behavior to return custom icon only on exact match?

There are some file names that have special icons, different for the icon related to the file extension.
Example: the .gitlab-ci.yml has its own icon, which is different from the icon for other .yml files.

That's great! But the custom icon is only returned if I call the get_icon function with the exact filename. If the special file is under another path, the default icon is returned:
If call :lua print(require('nvim-web-devicons').get_icon('.gitlab-ci.yml')) I get the special gitlab icon. (Great!)
But if I call :lua print(require('nvim-web-devicons').get_icon('otherdir/.gitlab-ci.yml')) I get default .yml icon.

The same happens if I define some special icon by myself, like package.json or .eslintrc.js.

This can be resolved by using the function vim.fn.fnamemodify with the flag ':t' to provide get_icon only the tail of the file path.

I would like to know if this is the intended behavior. If it is, I think a tip could be added to the README instructing the user about using vim.fn.fnamemodify to not miss the special icons.

I notice that using telescope.nvim. With the fuzzy finder, the special icons are rendered only if the file is in the vim current directory, otherwise the 'defaults' icons are displayed. I just want to check with you before submitting a PR to telescope about using vim.fn.fnamemodify to avoid this inconsistency.

Use filetype instead of extension

Hi! First of all, thanks for the nice plugin.

Some syntaxes could have multiple extensions associated, for example (yaml,yml), (clj,cljc,cljs,edn), (c, h), (markdown, md) and so on, while some files might also not have the extension but force a filetype by modeline, for example, so instead of having an entry for each extension, maybe it's better to rely on ft. WDYT?

Dealing with upper and lower cases in extensions

Some file extensions allow several forms which differ only in letter cases: '.r' and '.R', '.Rmd' and '.rmd', etc. Currently to account for this, manual extra search should be done (like devicons.get_icon(file_name, file_ext) or devicons.get_icon(string.lower(file_name), string.lower(file_ext), { default = true })).

Maybe it is a good idea to incorporate some form of case insensitiveness into plugin directly?

About default icon.

Hi, Some times we want get an icon that even it doesn't match the ext or name, so use unknown replace default more better and remove opts? If we dosen't find an icon in icon_data we return unknown icon. What do you think?

The icon for directory does not show up.

Hi,
As the title said, the icon for any directory does not display. I tried by overriding in the setup.
image
The icon for the test.js file is displayed as expected, however, the icon for other two dirs are not work.
Thank you!

I can't get colors to work

I can't get colors to work in nvim-tree or telescope. I have been troubleshooting this problem on and off for months. I am at my wits end, I give up. I'm dumping my config folder here in case you feel like figuring out what's breaking icon colors.

In short, my nvim-tree config looks like this:

require("nvim-web-devicons").setup{ default = true }

require("nvim-tree").setup {
  hijack_cursor = true,
  view = {
    width = 40
  }
}

Result:

image

Frustratingly, if I reload my plugin config (:so %) and open nvim-tree again, it now has colored icons, but telescope doesn't:

image

I have spent more hours troubleshooting this than I care to admit, shuffling things around, disabling various plugins, configuring plugins in different orders etc. If you have any suggestions for what else I can try, I'd appreciate it a lot.

Here is my nvim config: nvim-config.zip

Deferred highlighting with vim.schedule causes issue

The previous API was defininig the highlight groups synchronously. Now that vim.schedule is used, the function returns the HL group name but it's not defined yet because the scheduled function hasn't run yet.

Not sure why you've enabled that but I would tend to believe that this new behavior is incorrect.

Users of barbar.nvim who update their packages are all affected by this issue, LMK what's the ETA and resolution when you have more details.

Link: romgrk/barbar.nvim#98

How to change default global icon?

Hey @kyazdani42 , thanks so much for this port.

I'd like to change default_icon to something else

I tried

require'nvim-web-devicons'.setup {
 override = {
   default_icon = {
     icon = "",
     color = "#6d8086",
     name = "Default",
    }
  };
}

But didn't work for me

Thanks again

[Question] How do I get a `default_icon`?

Thank you for creating a wonderful library!

I wanted to get the default icon with a get_icon(), but I couldn't get it right, so I have a question for you.

It could not be obtained below.

local devicons = require'nvim-web-devicons'
print(devicons.get_icon('default_icon'))

But when I overruled it, I got it right.

local devicons = require'nvim-web-devicons'
devicons.setup({
  default = true,
  override = {
    ["default_icon"] = {
      icon = "xx",
      color = "#6d8086",
      name = "Default",
    }
  }
})

print(devicons.get_icon('default_icon'))
-- xx DevIconDefault

Should this change be made?

diff --git a/lua/nvim-web-devicons.lua b/lua/nvim-web-devicons.lua
index bb301cc..9b69048 100644
--- a/lua/nvim-web-devicons.lua
+++ b/lua/nvim-web-devicons.lua
@@ -851,7 +851,8 @@ local function setup(opts)

   icons = vim.tbl_extend("force", icons, user_icons.override or {});

-  table.insert(icons, default_icon)
+  -- table.insert(icons, default_icon)
+  icons["default_icon"] = default_icon
   for _, icon_data in pairs(icons) do
     if icon_data.color and icon_data.name then
       local hl_group = get_highlight_name(icon_data)

How to override multiple filetypes?

I'm trying to override both gitignore and gitconfig file icons. My current config looks like this:

git = {
    icon = '<icon>',
    color = '#e06c75',
    name = 'gitignore'
},

This works fine, but when I do something like name = ['gitconfig', 'gitignore'] or name = {'gitconfig', 'gitignore'} it doesn't work. Grateful for any tips on how to do this!

How to vim

I don't know how to re-apply the highlights could someone give me a code snippet, i have a single init.vim file

bug: Unable to override/add icons after the latest commit

The solution in the latest commit (1a94ff0) does not seem to be good as that will not allow anyone to add/override an icon.

I have yamatsum/nvim-nonicons installed which overrides some of the icons from nvim-web-devicons, which is successful because it calls the setup function first. Then, I also have my own setup which adds custom icons (which now fails) and then there's tamago324/lir.nvim which adds its own folder icon (which also fails).

A solution would be to expose an override function which would allow anyone to add/override an icon without doing the setup call.

Feature Request: enable an option to exclude predefined icons

Is there currently a way to disable the use of the predefined icons? I was thinking maybe it can be an option during the setup.

require('nvim-web-devicons').setup {
  override = {},     -- we define all our icons here
  predefined = false -- use none of the predefined icons
}

The reason for this is so that I can define a universal default icon for every single filetype. Can you suggest a better approach perhaps?

How to add an icon for certain extensions?

How to add an icon for certain extensions?

I don't really know how to formulate my question, but with devicons I could do this let g: WebDevIconsUnicodeDecorateFileNodesPatternSymbols ['. * Test. * \. Js $'] = 'ﭧ'
And the result was the following:
image

How can I achieve the same result with this plugin?

add docs

add documentation for developers and users on how to use/setup this plugin.

Use prefix for highlight groups

By conventions, plugins usually use a prefix rather than a suffix for their hl group names:

JavascriptDevIcon => DevIconJavascript

devicons highlight is no longer re-applied if re-sourcing init.vim

@kyazdani42 since #22 was merged and setup() is now only allowed to be called once, if you try and source your init.vim during an editing setting the highlights are no longer re-applied. I was solving this issue in nvim-bufferline by using an autocmd ColorScheme * lua.require'nvim-devicons'.setup() to re-apply the highlights since most colorschemes will clear the existing highlights if you re source your init.vim I think calling setup is now not possible more than once so you can't re-apply the highlights.

I think a solution could be adding the autocommand to the plugin directly? What are your thoughts? if you agree I can test if it works and make a PR later today?

How to change directory icon

my nerd font can't type the default directory icon
i want to change it to another one what is the directory extension

Im using telescope not nvim-tree

How to override icons that start with a dot?

require'nvim-web-devicons'.setup {
    -- your personnal icons can go here (to override)
    -- DevIcon will be appended to `name`
    override = {
        lua = {icon = "", color = colors.nord15, name = "lua"},
        .gitignore = {icon = "", color = colors.nord4, name = "GitIgnore"},
    },
    -- globally enable default icons (default to false)
    -- will get overriden by `get_icons` option
    default = true
}

This gives an error.

How do i properly override the .gitignore icons? (And others that start with a dot)

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

Some icons use RTL unicode characters and can mess up surrounding text

Some icons switch the active direction of text to RTL and affect the surrounding text. Specific examples are the latex icon (extension .tex) and the SVG icon. I know there are others as well, but #46 is a result of this issue specifically for the latex icon.

I don't have a PR yet (I could produce one if desired), but I was able to completely resolve these issues in my config by overriding the offending icons to add LTR Unicode direction isolates around the icon text. The Unicode consortium introduced these isolates to specifically help with issues like this. Text inside the isolate markers cannot affect the direction of the surrounding text, and as long as the terminal emulator properly supports the Unicode bidi algorithm, using the isolates fixes many of the rendering issues.

I've verified that if the icon text is surrounded with LTR isolate markers (LRI .. icon .. PDI), then the icons will no longer mess up the rendering of surrounding text if the terminal emulator properly applies the bidi algorithm (modern terminal emulators do). Isolates specifically do not affect the direction of the surrounding text so this won't affect rendering if the icon appears in RTL text.

Maybe the icons that use codepoints that are designated as RTL (Tex, SVG, etc) should have LTR isolate markers around the unicode codepoint. This would involve something like:

["tex"] = {
    icon = "<U+2066>ﭨ<U+2069>", -- actual utf-8 encoded codepoints instead, this is for demonstration
    color = "#3D6117",
    name = "Tex"
  };
...

I have this override in my config and it corrected rendering issues with telescope.nvim and fzf-lua when they rendered the tex icon in their popup windows.

Another possibility is changing the get_icon() function to wrap the icon text in the isolate markers before returning, possibly with a memoization.

Get icon by filetype

The icons are classified by filename and/or extension. It would be nice to be able to get an icon by filetype.

Eg vim's help files have the help filetype, but their extension is still .txt.

[Q] OSX support

Hi, how can I make it work with iterm2 on OSX?
I am using default iterm2 font - Monaco.

icon for org

The org icon is normally a unicorn. Have u ever come across it. If yes please add it. I have searched my pants of and I couldn't find it.

Icons are incorrectly labeled

Not sure what happened but it seems that the icons are named incorrectly. For example under the python label their seems to be a database icon and under the c label their is a icon that says npm. These files are from a direct git clone so I think these are the latest version.

image
image

File Icons does not work for nvimTree

As the title states. My file icons works for telescope and bufferline but not nvimTree.

Example that it does not work for nvimTree but does work for bufferline
image

Example that shows it works for telescope
image

Wrong devicon when .vimrc/.zshrc opened from startify screen

The devicons for files like .vimrc, .zshrc is incorrect when file is opened from vim-startify screen. The icons are correct if these files are opened directly using commands like :e .vimrc<CR>/ :e.zshrc<CR>. The same problem does not occur for most of the other file types (including files that end in .vim).

Steps to recreate:

  1. Install vim-startify
  2. Reopen nvim
  3. Open .vimrc file using usual command :e .vimrc<CR>.
  4. Close, and reopen nvim
  5. Open .vimrc file by pressing <CR> on .vimrc file in the MRU buffer list of vim-startify's startup screen.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.