mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-15 19:45:46 +08:00
fix(snippet): fix snippet key binding
This commit is contained in:
parent
00dd06a3a5
commit
9d80f93a85
@ -257,6 +257,15 @@ function! SpaceVim#layers#autocomplete#set_variable(var) abort
|
|||||||
|
|
||||||
endfunction
|
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
|
function! SpaceVim#layers#autocomplete#get_options() abort
|
||||||
|
|
||||||
return ['return_key_behavior',
|
return ['return_key_behavior',
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
local cmp = require('cmp')
|
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)
|
local feedkey = function(key, mode)
|
||||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
|
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
|
||||||
end
|
end
|
||||||
@ -8,16 +18,17 @@ cmp.setup({
|
|||||||
mapping = {
|
mapping = {
|
||||||
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
|
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
|
||||||
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
|
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
|
||||||
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
|
|
||||||
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
|
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
|
||||||
['<C-e>'] = cmp.mapping({
|
['<C-e>'] = cmp.mapping({
|
||||||
i = cmp.mapping.abort(),
|
i = cmp.mapping.abort(),
|
||||||
c = cmp.mapping.close(),
|
c = cmp.mapping.close(),
|
||||||
}),
|
}),
|
||||||
['<Tab>'] = function(fallback)
|
['<Tab>'] = 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('<plug>(neosnippet_expand_or_jump)', '')
|
feedkey('<plug>(neosnippet_expand_or_jump)', '')
|
||||||
elseif cmp.visible() then
|
elseif cmp.visible() and copt.auto_completion_return_key_behavior == 'complete' then
|
||||||
cmp.select_next_item()
|
cmp.select_next_item()
|
||||||
else
|
else
|
||||||
fallback()
|
fallback()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user