Files
dkelly-neovim/lua/dkelly/plugins/nvim-cmp.lua
2025-11-23 15:46:52 -06:00

71 lines
1.6 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

return {
"hrsh7th/nvim-cmp",
dependencies = {
-- basic sources
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
-- cmdline completion for `:` and `/`
"hrsh7th/cmp-cmdline", -- :contentReference[oaicite:0]{index=0}
-- LSP
"hrsh7th/cmp-nvim-lsp", -- :contentReference[oaicite:1]{index=1}
-- Treesitter source
"ray-x/cmp-treesitter", -- :contentReference[oaicite:2]{index=2}
"rafamadriz/friendly-snippets",
-- icons
"onsails/lspkind.nvim",
},
config = function()
local cmp = require("cmp")
local lspkind = require("lspkind")
-- load friendly-snippets
-- nicer completions menu
vim.opt.completeopt = "menu,menuone,preview,noselect"
cmp.setup({
mapping = cmp.mapping.preset.insert({
["<C-k>"] = cmp.mapping.select_prev_item(),
["<C-j>"] = cmp.mapping.select_next_item(),
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = false }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "treesitter" },
{ name = "buffer" },
{ name = "path" },
}),
formatting = {
format = lspkind.cmp_format({
maxwidth = 50,
ellipsis_char = "...",
}),
},
})
-- Commandline “:” → cmdline + path
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = "path" },
{ name = "cmdline" },
},
})
-- Search “/” → buffer
cmp.setup.cmdline("/", {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = "buffer" },
},
})
end,
}