Last active
October 12, 2021 13:37
-
-
Save joelpalmer/e348db324da93675d3e6ff9c482f2b02 to your computer and use it in GitHub Desktop.
nvim-cmp config with Lua (completion/init.lua) using lspkind
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Setup nvim-cmp | |
local cmp = require "cmp" | |
local lspkind = require "lspkind" | |
cmp.setup { | |
snippet = { | |
expand = function(args) | |
vim.fn["vsnip#anonymous"](args.body) | |
end, | |
}, | |
mapping = { | |
["<C-d>"] = cmp.mapping.scroll_docs(-4), | |
["<C-f>"] = cmp.mapping.scroll_docs(4), | |
["<C-Space>"] = cmp.mapping.complete(), | |
["<CR>"] = cmp.mapping.confirm { select = true }, | |
-- Right is for ghost_text to behave like terminal | |
["<Right>"] = cmp.mapping.confirm { select = true }, | |
["<C-e>"] = cmp.mapping.close(), | |
["<Down>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Select }, | |
["<Up>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Select }, | |
}, | |
experimental = { | |
ghost_text = true, | |
}, | |
documentation = { | |
border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, | |
}, | |
sources = { | |
-- 'crates' is lazy loaded | |
{ name = "nvim_lsp" }, | |
{ name = "treesitter" }, | |
{ name = "vsnip" }, | |
{ name = "path" }, | |
{ | |
name = "buffer", | |
opts = { | |
get_bufnrs = function() | |
return vim.api.nvim_list_bufs() | |
end, | |
}, | |
}, | |
{ name = "spell" }, | |
}, | |
formatting = { | |
format = function(entry, vim_item) | |
vim_item.kind = string.format("%s %s", lspkind.presets.default[vim_item.kind], vim_item.kind) | |
-- See where 'Text' is coming from in you completion menu | |
vim_item.menu = ({ | |
nvim_lsp = "ﲳ", | |
nvim_lua = "", | |
treesitter = "", | |
path = "ﱮ", | |
buffer = "", | |
zsh = "", | |
vsnip = "", | |
spell = "暈", | |
})[entry.source.name] | |
return vim_item | |
end, | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment