lspkind.nvim

repository·master·Indexed 23 days ago

https://github.com/onsails/lspkind.nvim

A Neovim plugin that adds VS Code-style pictograms to completion menus for LSP, snippets, and path completions to improve visual scanability. It supports Neovim 0.7+ and integrates with nvim-cmp and blink.cmp. Users can choose between Nerd Fonts or VS Code Codicons presets and customize symbols via a symbol map.

Tokens
1.7K
Snippets
3
Records
5
Agent score
33%

What's inside lspkind.nvim

  1. Overview of lspkind.nvim

    master
    lspkind.nvim provides VS Code–style pictograms for Neovim completion items (LSP, snippets, paths, etc.). It improves the scanability of completion menus by adding a consistent iconography layer to indicate the intent and type of each item.
  2. Configure lspkind.nvim for vanilla Neovim LSP

    master

    You can initialize lspkind.nvim using require('lspkind').init() or its alias require('lspkind').setup().

    Configuration Options

    • mode: Defines how annotations are shown.
      • Options: 'text', 'text_symbol', 'symbol_text', 'symbol' (default: 'symbol')
    • preset: Selects the icon set.
      • Options: 'default' (requires Nerd Fonts) or 'codicons' (requires VS Code Codicons). (default: 'default')
    • symbol_map: A table to override preset symbols for specific kinds (e.g., Text, Method, Function, etc.).
    -- setup() is also available as an alias
    require('lspkind').init({
        -- defines how annotations are shown
        -- default: symbol
        -- options: 'text', 'text_symbol', 'symbol_text', 'symbol'
        mode = 'symbol_text',
    
        -- default symbol map
        -- can be either 'default' (requires nerd-fonts font) or
        -- 'codicons' for codicon preset (requires vscode-codicons font)
        --
        -- default: 'default'
        preset = 'codicons',
    
        -- override preset symbols
        --
        -- default: {}
        symbol_map = {
          Text = "󰉿",
          Method = "󰆧",
          Function = "󰊕",
          Constructor = "",
          Field = "󰜢",
          Variable = "󰀫",
          Class = "󰠱",
          Interface = "",
          Module = "",
          Property = "󰜢",
          Unit = "󰑭",
          Value = "󰎠",
          Enum = "",
          Keyword = "󰌋",
          Snippet = "",
          Color = "󰏘",
          File = "󰈙",
          Reference = "󰈇",
          Folder = "󰉋",
          EnumMember = "",
          Constant = "󰏿",
          Struct = "󰙅",
          Event = "",
          Operator = "󰆕",
          TypeParameter = "",
        },
    })
  3. Integrate lspkind.nvim with blink.cmp

    master

    To use lspkind icons in blink.cmp, define a custom text function for the kind_icon component in your completion.menu.draw.components configuration. Access the symbol via require('lspkind').symbol_map[ctx.kind].

    completion = {
      menu = {
        draw = {
          components = {
            kind_icon = {
              text = function(ctx)
                return require('lspkind').symbol_map[ctx.kind] or ''
              end,
            },
          },
        },
      },
    }
  4. Integrate lspkind.nvim with nvim-cmp

    master

    Use lspkind.cmp_format within your nvim-cmp configuration to apply icons and formatting to the completion menu.

    cmp_format Options

    • maxwidth: An object defining maximum character widths for menu (labelDetails) and abbr (suggestion item). Can be a number or a function.
    • ellipsis_char: The character used when the menu exceeds maxwidth (e.g., '...').
    • show_labelDetails: Boolean to enable/disable showing label details in the menu (default: false).
    • before: A callback function function(entry, vim_item) that is called before lspkind applies its modifications, allowing for custom control over the vim_item.
    local lspkind = require('lspkind')
    cmp.setup {
      formatting = {
        fields = { 'abbr', 'icon', 'kind', 'menu' },
        format = lspkind.cmp_format({
          maxwidth = {
            -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
            -- can also be a function to dynamically calculate max width such as
            -- menu = function() return math.floor(0.45 * vim.o.columns) end,
            menu = 50, -- leading text (labelDetails)
            abbr = 50, -- actual suggestion item
          },
          ellipsis_char = '...', -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
          show_labelDetails = true, -- show labelDetails in menu. Disabled by default
    
          -- The function below will be called before any actual modifications from lspkind
          -- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30))
          before = function (entry, vim_item)
            -- ...
            return vim_item
          end
        })
      }
    }