dotfiles/config/linux-dev/nvim/lua/plugins/completion.lua
2025-02-24 09:51:41 +00:00

61 lines
1.5 KiB
Lua

return {
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-path",
},
config = function()
local cmp = require("cmp")
cmp.setup({
window = {
completion = {
border = "single",
-- or border = true for default border
},
documentation = {
border = "single",
},
},
completion = { completeopt = "menu,menuone,noselect" }, -- This ensures nothing is auto-selected
sources = cmp.config.sources({
{ name = "nvim_lsp" }, -- from language server
{ name = "buffer" }, -- from current buffer
{ name = "path" }, -- for file paths
}),
mapping = cmp.mapping.preset.insert({
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Insert })
else
fallback()
end
end),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item({ behavior = cmp.SelectBehavior.Insert })
else
fallback()
end
end),
["<C-e>"] = cmp.mapping.abort(), -- This closes the completion menu
["<C-u>"] = cmp.mapping(function(fallback)
if cmp.visible() and cmp.get_selected_entry() then
cmp.scroll_docs(-4)
else
fallback()
end
end),
["<C-d>"] = cmp.mapping(function(fallback)
if cmp.visible() and cmp.get_selected_entry() then
cmp.scroll_docs(4)
else
fallback()
end
end),
}),
})
end,
}