diff --git a/autoload/SpaceVim/layers/autocomplete.vim b/autoload/SpaceVim/layers/autocomplete.vim index 34f1962ea..7bbbb473e 100644 --- a/autoload/SpaceVim/layers/autocomplete.vim +++ b/autoload/SpaceVim/layers/autocomplete.vim @@ -257,6 +257,15 @@ function! SpaceVim#layers#autocomplete#set_variable(var) abort endfunction +function! SpaceVim#layers#autocomplete#get_variable() abort + + return { + \ 'auto_completion_tab_key_behavior' : s:tab_key_behavior, + \ } + + +endfunction + function! SpaceVim#layers#autocomplete#get_options() abort return ['return_key_behavior', diff --git a/lua/config/nvim-cmp.lua b/lua/config/nvim-cmp.lua index 62e620028..8de0121c3 100644 --- a/lua/config/nvim-cmp.lua +++ b/lua/config/nvim-cmp.lua @@ -1,5 +1,15 @@ local cmp = require('cmp') +local copt = vim.fn['SpaceVim#layers#autocomplete#get_variable']() + + +-- 1. `auto_completion_return_key_behavior` set the action to perform + -- when the `Return`/`Enter` key is pressed. the possible values are: + -- - `complete` completes with the current selection + -- - `smart` completes with current selection and expand snippet or argvs + -- - `nil` + -- By default it is `complete`. + local feedkey = function(key, mode) vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) end @@ -8,16 +18,17 @@ cmp.setup({ mapping = { [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), - [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), [''] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. [''] = cmp.mapping({ i = cmp.mapping.abort(), c = cmp.mapping.close(), }), [''] = function(fallback) - if vim.fn['neosnippet#expandable_or_jumpable']() == 1 then + if copt.auto_completion_return_key_behavior == 'smart' + and vim.fn['neosnippet#expandable_or_jumpable']() == 1 + then feedkey('(neosnippet_expand_or_jump)', '') - elseif cmp.visible() then + elseif cmp.visible() and copt.auto_completion_return_key_behavior == 'complete' then cmp.select_next_item() else fallback()