From cc49f5339ed85aa306b6b6a53e508f36248e79f8 Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Tue, 21 Feb 2023 16:53:22 +0000 Subject: [PATCH] refactor(vim): simplify the tab behaviour in completion The biggest change here is that I am no longer cycling though completion items as the first thing. Tab will now mainly control the snippet jumps in completion not items. Completion items can be used exclusively with and and to complete the selected item. If the completion menu is open and is pressed, this will select and complete the first item. I will soon be able to remove the and mappings when my muscle memory adapts as this will now be controlled with tab. --- site-modules/core/files/vim/init.vim | 3 --- .../core/files/vim/plugin/completion.lua | 23 +++---------------- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/site-modules/core/files/vim/init.vim b/site-modules/core/files/vim/init.vim index f55254f..3a5a533 100644 --- a/site-modules/core/files/vim/init.vim +++ b/site-modules/core/files/vim/init.vim @@ -74,6 +74,3 @@ nnoremap " ignored from command-t file searches. let g:CommandTWildIgnore="*/node_modules/*,*/vendor/*,*/runtime/*,*/public_html/*,*/pack/*" -" Required for complietion with nvim-cmp -set completeopt=menu,menuone,noselect - diff --git a/site-modules/core/files/vim/plugin/completion.lua b/site-modules/core/files/vim/plugin/completion.lua index b5f60d8..6483675 100644 --- a/site-modules/core/files/vim/plugin/completion.lua +++ b/site-modules/core/files/vim/plugin/completion.lua @@ -28,11 +28,6 @@ Text = "", Operator = "", } -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 - cmp.setup({ mapping = cmp.mapping.preset.insert({ [''] = cmp.get_config().mapping[''], @@ -41,29 +36,17 @@ cmp.setup({ [''] = function() luasnip.jump(-1) end, [''] = cmp.mapping.abort(), - [''] = cmp.mapping(function(_fallback) - if cmp.visible() then - cmp.confirm({ select = true }) - else - vim.api.nvim_feedkeys('\n', 'nt', false) - end - end, { 'i', 's' }), + [''] = cmp.mapping.confirm({ select = true }), [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then + if luasnip.expand_or_jumpable() then luasnip.expand_or_jump() - elseif has_words_before() then - cmp.complete() else fallback() end end, { "i", "s" }), [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then + if luasnip.jumpable(-1) then luasnip.jump(-1) else fallback()