feat(nvim): change cmp binds again
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-08-07 10:41:41 -04:00
parent c3fa6e92ee
commit dafb2cf8ce
2 changed files with 8 additions and 21 deletions

View file

@ -78,10 +78,7 @@ in {
cmp-nvim-lsp cmp-nvim-lsp
cmp-path cmp-path
cmp-spell cmp-spell
cmp-treesitter
cmp-vsnip
vim-vsnip vim-vsnip
friendly-snippets
]) ])
++ [ ++ [
{ {

View file

@ -1,26 +1,16 @@
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0));
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil;
end;
local cmp = require('cmp'); local cmp = require('cmp');
local cmp_autopairs = require('nvim-autopairs.completion.cmp');
-- If you want insert `(` after select function or method item
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
cmp.event:on( cmp.event:on(
'confirm_done', 'confirm_done',
cmp_autopairs.on_confirm_done() cmp_autopairs.on_confirm_done()
) );
cmp.setup({ cmp.setup({
sources = { sources = {
{ name = 'nvim_lsp' }, { name = 'nvim_lsp' },
{ name = 'cmp_tabnine' },
{ name = 'treesitter' },
{ name = 'buffer' }, { name = 'buffer' },
{ name = 'path' }, { name = 'path' },
{ name = 'vsnip' },
}, },
snippet = { snippet = {
@ -31,14 +21,12 @@ cmp.setup({
mapping = { mapping = {
-- Confirm selection -- Confirm selection
['<CR>'] = cmp.mapping.confirm({ select = true }), ['<Right>'] = cmp.mapping.confirm({ select = true }),
-- Next selection -- Next selection
['<Down>'] = cmp.mapping(function(fallback) ['<Down>'] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_next_item(); cmp.select_next_item();
elseif has_words_before() then
cmp.complete();
else else
fallback(); fallback();
end; end;
@ -48,9 +36,11 @@ cmp.setup({
}), }),
-- Previous selection -- Previous selection
['<Up>'] = cmp.mapping(function() ['<Up>'] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item(); cmp.select_prev_item();
else
fallback();
end; end;
end, { end, {
'i', 'i',