From 62ba0e08fb99c36e35f7490acb0fd511c0a3d054 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Mon, 2 May 2022 07:27:33 +0200 Subject: [PATCH] Feat: set nice completion mapping with tab and enter --- nvim/.config/nvim/lua/completion.lua | 34 +++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/nvim/.config/nvim/lua/completion.lua b/nvim/.config/nvim/lua/completion.lua index 245bfd7..087ec24 100644 --- a/nvim/.config/nvim/lua/completion.lua +++ b/nvim/.config/nvim/lua/completion.lua @@ -41,7 +41,7 @@ local lsp_symbols = { local cmp = require'cmp' cmp.setup{ completion = { - completeopt = 'menuone,noselect', + completeopt = 'menuone,noinsert,noselect', }, formatting = { format = function(entry, vim_item) @@ -64,8 +64,27 @@ cmp.setup{ end, }, mapping = { - -- [""] = cmp.mapping.confirm({select = true, behavior = cmp.ConfirmBehavior.Replace}), - [""] = cmp.mapping.confirm({select = true, behavior = cmp.ConfirmBehavior.Insert}), + [""] = cmp.mapping.confirm({select = false, behavior = cmp.ConfirmBehavior.Replace}), + -- [""] = cmp.mapping.confirm({select = true, behavior = cmp.ConfirmBehavior.Insert}), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. + end + end, { "i", "s" }), + + [""] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("(vsnip-jump-prev)", "") + end + end, { "i", "s" }), }, sources = { { name = 'vsnip' }, @@ -91,5 +110,14 @@ cmp.setup{ }, } +-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline('/', { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer' } + } +}) + + vim.cmd [[autocmd FileType TelescopePrompt lua require('cmp').setup.buffer { enabled = false }]] vim.g.vsnip_snippet_dir = '~/.config/nvim/vsnips'