Skip to content

Commit

Permalink
chore(neovim): tweak nvim-cmp config
Browse files Browse the repository at this point in the history
  • Loading branch information
izumin5210 committed Dec 7, 2024
1 parent 88914a3 commit 9becc84
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions config/.config/nvim/lua/plugins/edit/config/nvim-cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,44 @@ function M.init()
})
end

-- https://github.com/zbirenbaum/copilot-cmp/tree/b6e5286?tab=readme-ov-file#tab-completion-configuration-highly-recommended
local has_words_before = function()
if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then
return false
end
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_text(0, line - 1, 0, line - 1, col, {})[1]:match("^%s*$") == nil
end

function M.setup()
local cmp = require("cmp")

cmp.setup({
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
completion = {
completeopt = "menu,menuone,noinsert",
},
mapping = cmp.mapping.preset.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(),
["<CR>"] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }), -- zbirenbaum/copilot-cmp
-- https://github.com/zbirenbaum/copilot-cmp/tree/b6e5286?tab=readme-ov-file#tab-completion-configuration-highly-recommended
["<Tab>"] = vim.schedule_wrap(function(fallback)
if cmp.visible() and has_words_before() then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
else
fallback()
end
end),
-- ["<CR>"] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }),
["<CR>"] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "copilot" },
{ name = "path" },
}, {
{ name = "buffer" },
}, {
name = "lazydev",
group_index = 0,
{ name = "copilot", group_index = 1, priority = 1000 },
{ name = "nvim_lsp", group_index = 1, priority = 100 },
{ name = "path", group_index = 1, priority = 10 },
{ name = "buffer", group_index = 1, priority = 1 },
{ name = "lazydev", group_index = 0 },
}),
-- https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance#how-to-get-types-on-the-left-and-offset-the-menu
window = {
Expand Down

0 comments on commit 9becc84

Please sign in to comment.