Make nvim-cmp less annoying

This commit is contained in:
Erik Stambaugh 2024-06-18 07:00:40 -07:00
parent 37366c5d0c
commit 96372bd1de

View file

@ -112,6 +112,19 @@ require("lazy").setup({
local cmp = require'cmp' local cmp = require'cmp'
cmp.setup({ cmp.setup({
-- https://github.com/hrsh7th/nvim-cmp/wiki/Advanced-techniques#disabling-completion-in-certain-contexts-such-as-comments
enabled = function()
-- disable completion in comments
local context = require 'cmp.config.context'
-- keep command mode completion enabled when cursor is in a comment
if vim.api.nvim_get_mode().mode == 'c' then
return true
else
return not context.in_treesitter_capture("comment")
and not context.in_syntax_group("Comment")
end
end,
snippet = { snippet = {
-- REQUIRED - you must specify a snippet engine -- REQUIRED - you must specify a snippet engine
expand = function(args) expand = function(args)
@ -126,13 +139,21 @@ require("lazy").setup({
-- completion = cmp.config.window.bordered(), -- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(), -- documentation = cmp.config.window.bordered(),
}, },
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4), -- don't use up/down arrows. Different from the suggested "merge", this replaces the keymaps completely
['<C-f>'] = cmp.mapping.scroll_docs(4), -- I wouldn't have to have done this if I used HJKL motions when I edit rather than arrow keys
['<C-Space>'] = cmp.mapping.complete(), mapping = {
['<C-e>'] = cmp.mapping.abort(), ['<C-j>'] = { i = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), },
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. ['<C-k>'] = { i = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), },
}), ['<C-n>'] = { i = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), },
['<C-p>'] = { i = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), },
['<C-y>'] = { i = cmp.mapping.confirm({ select = false }), },
['<C-e>'] = { i = cmp.mapping.abort(), },
['<C-Space>'] = { i = cmp.mapping.complete(), },
['<C-b>'] = { i = cmp.mapping.scroll_docs(-4) },
['<C-f>'] = { i = cmp.mapping.scroll_docs(4) },
},
sources = cmp.config.sources({ sources = cmp.config.sources({
{ name = 'nvim_lsp' }, { name = 'nvim_lsp' },
-- { name = 'vsnip' }, -- For vsnip users. -- { name = 'vsnip' }, -- For vsnip users.