From 54cc8adb1426f9c9bff88c48b9021946513546af Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 16 Jan 2017 20:50:00 +0800 Subject: [PATCH] Improve tab in insert mode --- autoload/SpaceVim/default.vim | 4 ++-- autoload/SpaceVim/mapping.vim | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/autoload/SpaceVim/default.vim b/autoload/SpaceVim/default.vim index bf1beb3ff..4d92fb2a2 100644 --- a/autoload/SpaceVim/default.vim +++ b/autoload/SpaceVim/default.vim @@ -147,9 +147,9 @@ function! SpaceVim#default#SetMappings() abort "mapping "全局映射 "也可以通过'za'打开或者关闭折叠 - imap zvim#tab() + imap SpaceVim#mapping#tab() smap neosnippet#expandable_or_jumpable() ? "\(neosnippet_expand_or_jump)" : "\" - inoremap zvim#enter() + inoremap SpaceVim#mapping#enter() inoremap =MyLeaderTabfunc() inoremap pumvisible() ? "\" : "\" inoremap pumvisible() ? "\" : "\" diff --git a/autoload/SpaceVim/mapping.vim b/autoload/SpaceVim/mapping.vim index b95518ec9..778042746 100644 --- a/autoload/SpaceVim/mapping.vim +++ b/autoload/SpaceVim/mapping.vim @@ -15,3 +15,44 @@ function! SpaceVim#mapping#def(type,key,value,desc,...) abort let cmd = len(a:000) > 0 ? a:000[0] : a:value call add(g:unite_source_menu_menus.CustomKeyMaps.command_candidates, [description,cmd]) endfunction + +function! SpaceVim#mapping#tab() abort + if getline('.')[col('.')-2] ==# '{'&& pumvisible() + return "\" + endif + if !index(g:spacevim_plugin_groups, 'autocompletion') == -1 + if neosnippet#expandable() && getline('.')[col('.')-2] ==# '(' && !pumvisible() + return "\(neosnippet_expand)" + elseif neosnippet#jumpable() + && getline('.')[col('.')-2] ==# '(' && !pumvisible() + && !neosnippet#expandable() + return "\(neosnippet_jump)" + elseif neosnippet#expandable_or_jumpable() && getline('.')[col('.')-2] !=#'(' + return "\(neosnippet_expand_or_jump)" + elseif pumvisible() + return "\" + else + return "\" + endif + elseif pumvisible() + return "\" + else + return "\" + endif +endfunction + +function! SpaceVim#mapping#enter() abort + if pumvisible() + if getline('.')[col('.') - 2]==# '{' + return "\" + elseif g:spacevim_autocomplete_method ==# 'neocomplete'||g:spacevim_autocomplete_method ==# 'deoplete' + return "\" + else + return "\a" + endif + elseif getline('.')[col('.') - 2]==#'{'&&getline('.')[col('.')-1]==#'}' + return "\\ko" + else + return "\" + endif +endfunction