AstroNvim / user_example

An example user configuration with a split up structure
231 stars 781 forks source link

support icons in which-key menu #13

Closed practicalli-johnny closed 1 year ago

practicalli-johnny commented 1 year ago

AstroNvim uses icons for many of the top level menu items in which-key.

Is it possible to use icons with key bindings defined in the AstroNvim/user_example config, e.g. mappings.lua

I would like to include icons for menu items from packages I have added to my own user config (forked from this example template).

Packages are added via the Astrocommunity or directly using the lazy syntax.

Thank you.

References

mehalter commented 1 year ago

Yup! You just need to add an icon to the keymap description

practicalli-johnny commented 1 year ago

Do you have an example? e.g. I'd like to add a GitHub icon for the Octo menu.

This code in mappings.lua seems to work for the Git icon, but there doesnt seem to be a GitHub icon


local utils = require "astronvim.utils"
local get_icon = utils.get_icon

return {
  n = {
    ["<leader>O"] = { name = get_icon("Git", 1, true) .. " Octo" },
  },
}

I am assuming only icons available via lspkind can be used, so only those from https://github.com/AstroNvim/AstroNvim/tree/main/lua/astronvim/icons

Unless I have missed something, its not just possible to use any icon from NerdFonts, only those from lspkind (unless I write a different function to get the font - which may take a while to figure out as I am new to Lua and Neovim)

I'll leave this as not possible for the moment and get on with learning AstroNvim.

mehalter commented 1 year ago

@practicalli-john yes you are correct that get_icon is only there to get AstroNvim UI icons. You can either customize the icons to add new ones or change our UI icons (here are docs for customizing icons: https://astronvim.com/Recipes/icons) or you can just copy/paste any nerdfont icon into the description. Here is the nerd font cheat sheet that you can use to look up any icon and copy/paste it into the description and not use the get_icon function: https://www.nerdfonts.com/cheat-sheet

practicalli-johnny commented 1 year ago

Ah, yes, I can copy nerd fonts icons from the cheat-sheet website into the name or desc value for a mapping. The cheat-sheet is a great way to find an icon and then copy its bitmap into the string.

    -- Menu mappings
    ["<leader>gn"] = { name = " Neogit" }, -- Neogit menu
    ["<leader>G"] = { name = "îȘ„ GitHub" }, -- Octo menu

GitHub web pages doesnt render the nerd font bitmaps though in its web pages 😞

Seems obvious now I know it 😉

Thank you.