nvim/lua/plugins/cmp.lua

75 lines
2.7 KiB
Lua
Raw Permalink Normal View History

2024-06-17 15:22:39 +07:00
return {
{
"hrsh7th/cmp-path",
enabled = false,
2024-06-17 15:22:39 +07:00
},
{
"hrsh7th/nvim-cmp",
enabled = true,
dependencies = {
"hrsh7th/cmp-cmdline",
"hrsh7th/cmp-nvim-lsp-document-symbol",
"https://codeberg.org/FelipeLema/cmp-async-path.git",
-- "hrsh7th/cmp-nvim-lsp-signature-help",
{ "lukas-reineke/cmp-rg", enabled = vim.fn.exepath "rg" ~= "" },
},
event = { "InsertEnter", "CmdlineEnter" },
opts = function(_, opts)
local cmp = require "cmp"
table.insert(opts.sources, 3, { name = "async_path" })
2024-08-14 21:15:45 +07:00
opts.window = {
completion = cmp.config.window.bordered(),
}
2024-06-17 15:22:39 +07:00
if vim.fn.exepath "rg" ~= "" then
table.insert(opts.sources, 4, { name = "rg" })
end
2024-06-17 15:22:39 +07:00
opts.preselect = cmp.PreselectMode.None
2024-06-17 15:22:39 +07:00
opts.mapping = cmp.mapping.preset.insert {
["<cr>"] = function(fallback)
cmp.abort()
fallback()
end,
["<c-cr>"] = cmp.mapping.confirm { select = true },
["<C-n>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
["<C-p>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<S-CR>"] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}, -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}
2024-06-17 15:22:39 +07:00
---@diagnostic disable-next-line: missing-fields
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources {
{ name = "async_path" },
{
name = "cmdline",
option = {
ignore_cmds = { "Man", "!" },
},
2024-06-17 15:22:39 +07:00
},
},
})
2024-06-17 15:22:39 +07:00
---@diagnostic disable-next-line: missing-fields
cmp.setup.cmdline("/", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources {
{ name = "nvim_lsp_document_symbol" },
{ name = "buffer" },
},
})
2024-06-17 15:22:39 +07:00
return opts
end,
},
2024-06-17 15:22:39 +07:00
}