lspkind.nvim
repository·master·Indexed 23 days ago
https://github.com/onsails/lspkind.nvimA 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.
What's inside lspkind.nvim
- 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.
Requirements for lspkind.nvim
masterTo use lspkind.nvim, you need:
- Neovim 0.7+
- A patched icon font:
- Nerd Fonts if using
preset = 'default' - VS Code Codicons if using
preset = 'codicons'
- Nerd Fonts if using
Configure lspkind.nvim for vanilla Neovim LSP
masterYou can initialize lspkind.nvim using
require('lspkind').init()or its aliasrequire('lspkind').setup().Configuration Options
mode: Defines how annotations are shown.- Options:
'text','text_symbol','symbol_text','symbol'(default:'symbol')
- Options:
preset: Selects the icon set.- Options:
'default'(requires Nerd Fonts) or'codicons'(requires VS Code Codicons). (default:'default')
- Options:
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 = "", }, })Integrate lspkind.nvim with blink.cmp
masterTo use lspkind icons in
blink.cmp, define a custom text function for thekind_iconcomponent in yourcompletion.menu.draw.componentsconfiguration. Access the symbol viarequire('lspkind').symbol_map[ctx.kind].completion = { menu = { draw = { components = { kind_icon = { text = function(ctx) return require('lspkind').symbol_map[ctx.kind] or '' end, }, }, }, }, }Integrate lspkind.nvim with nvim-cmp
masterUse
lspkind.cmp_formatwithin yournvim-cmpconfiguration to apply icons and formatting to the completion menu.cmp_format Options
maxwidth: An object defining maximum character widths formenu(labelDetails) andabbr(suggestion item). Can be a number or a function.ellipsis_char: The character used when the menu exceedsmaxwidth(e.g.,'...').show_labelDetails: Boolean to enable/disable showing label details in the menu (default:false).before: A callback functionfunction(entry, vim_item)that is called before lspkind applies its modifications, allowing for custom control over thevim_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 }) } }