Skip to content

rainstormstudio/nerd-icons.el

Repository files navigation

nerd-icons.el - A Library for Nerd Font icons

https://melpa.org/packages/nerd-icons-badge.svg

Nerd-icons.el is a library for easily using Nerd Font icons inside Emacs, an alternative to all-the-icons.

It works on both GUI and terminal! You only need a Nerd Font installed on your system.

It is inspired by all-the-icons, icons-in-terminal, vim-devicons, and nvim-web-devicons.

in GUI: screenshots/demo.png

in terminal: screenshots/demo-terminal.png

Installing Fonts

Please go to Nerd Fonts website and get a Nerd font. After installing the font on your machine, you need to set nerd-icons-font-family to match its font name so that the font can be properly used under GUI. If you want Nerd Fonts to work under a terminal, please change your terminal’s font to a Nerd font.

If the Nerd Font you installed does not display correctly (e.g. appear cut off), it is recommended to use Symbols Nerd Fonts Mono (Symbols Nerd Font). You can use M-x nerd-icons-install-fonts to install Symbols Nerd Fonts Mono for you. Note that for Windows you’ll need to manually install the font after you used this function.

Usage

nerd-icons is on Melpa. You can install it with built-in M-x package-install

(require 'nerd-icons)

or using use-package

(use-package nerd-icons
  ;; :custom
  ;; The Nerd Font you want to use in GUI
  ;; "Symbols Nerd Font Mono" is the default and is recommended
  ;; but you can use any other Nerd Font if you want
  ;; (nerd-icons-font-family "Symbols Nerd Font Mono")
  )

insert icons

  • use icon based on category
    • nerd-icons-icon-for-dir
    • nerd-icons-icon-for-file
    • nerd-icons-icon-for-extension
    • nerd-icons-icon-for-mode
    • nerd-icons-icon-for-url
    • nerd-icons-icon-for-buffer

    example:

    (insert (nerd-icons-icon-for-file "init.el"))
    ;; Inserts an icon for Emacs Lisp
        
  • use icon directly
    • nerd-icons-ipsicon
    • nerd-icons-octicon
    • nerd-icons-pomicon
    • nerd-icons-powerline
    • nerd-icons-faicon
    • nerd-icons-wicon
    • nerd-icons-sucicon
    • nerd-icons-devicon
    • nerd-icons-codicon
    • nerd-icons-flicon
    • nerd-icons-mdicon

    example:

    (insert (nerd-icons-faicon "nf-fa-gitlab"))
    ;; Inserts a Gitlab icon
        
  • insert icon interactively (M-x functions)
    • nerd-icons-insert
    • nerd-icons-insert-ipsicon
    • nerd-icons-insert-octicon
    • nerd-icons-insert-pomicon
    • nerd-icons-insert-powerline
    • nerd-icons-insert-faicon
    • nerd-icons-insert-wicon
    • nerd-icons-insert-sucicon
    • nerd-icons-insert-devicon
    • nerd-icons-insert-codicon
    • nerd-icons-insert-flicon
    • nerd-icons-insert-mdicon

customize icons

You can customize the icons via nerd-icons-extension-icon-alist, nerd-icons-regexp-icon-alist and nerd-icons-mode-icon-alist, etc.

For example,

(add-to-list 'nerd-icons-extension-icon-alist '("epub" nerd-icons-faicon "nf-fa-book" :face nerd-icons-green))

Glyph Sets

Glyph SetprefixPoint Rangeinsert function
Seti-UI + Customnf-seti-, nf-custom-e5fa - e631nerd-icons-sucicon
Deviconsnf-dev-e700 - e7c5nerd-icons-devicon
Font Awesomenf-fa-f000 - f2e0nerd-icons-faicon
Font Awesome Extensionnf-fae-e200 - e2a9nerd-icons-faicon
Material Design Iconsnf-md-f500 - fd46nerd-icons-mdicon
Weathernf-weather-e300 - e3ebnerd-icons-wicon
Octiconsnf-oct-f400 - f4a9, 2665, 26A1nerd-icons-octicon
Powerline Symbolsnf-pl-e0a0 - e0a2, e0b0 - e0b3nerd-icons-powerline
Powerline Extra Symbolsnf-ple-e0a3, e0b4 - e0c8, e0ca, e0cc - e0d4nerd-icons-powerline
IEC Power Symbolsnf-iec-23fb - 23fe, 2b58nerd-icons-ipsicon
Font Logosnf-linux-f300 - f32dnerd-icons-flicon
Pomiconsnf-pom-e000 - e00anerd-icons-pomicon
Codiconsnf-cod-ea60 - ebebnerd-icons-codicon

Please check Nerd Fonts Glyph Sets and Code Points for more information.

Related Packages

use nerd-icons with dirvish

sample configuration:

(use-package dirvish
  :init
  (dirvish-override-dired-mode)
  :config
  (setq dirvish-mode-line-format
        '(:left (sort symlink) :right (omit yank index)))
  (setq dirvish-mode-line-height 10)
  (setq dirvish-attributes
        '(nerd-icons file-time file-size collapse subtree-state vc-state git-msg))
  (setq dirvish-subtree-state-style 'nerd)
  (setq delete-by-moving-to-trash t)
  (setq dirvish-path-separators (list
                                 (format "  %s " (nerd-icons-codicon "nf-cod-home"))
                                 (format "  %s " (nerd-icons-codicon "nf-cod-root_folder"))
                                 (format " %s " (nerd-icons-faicon "nf-fa-angle_right"))))
  (setq dired-listing-switches
        "-l --almost-all --human-readable --group-directories-first --no-group")
  (dirvish-peek-mode) ; Preview files in minibuffer
  (dirvish-side-follow-mode) ; similar to `treemacs-follow-mode'
)