我试图让vim允许我用tab键遍历自动完成弹出列表.它适用于制表符,但不适用于s-tab(shift-tab).在应用CP之前,似乎shift-tab会以某种方式取消自动完成菜单
有人有任何想法吗?
function InsertTabWrapper(direction)
if pumvisible()
if "forward" == a:direction
return "\<C-N>"
else
return "\<C-P>"
endif
endif
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-x>\<c-o>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper("forward")<cr>
inoremap <s-tab> <c-r>InsertTabWrapper("backward")<cr>
Run Code Online (Sandbox Code Playgroud)
您<c-r>在<s-tab>映射后错过了等号"=" .
但是,我建议这样做:
function! InsertTabWrapper()
if pumvisible()
return "\<c-n>"
endif
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-x>\<c-o>"
endif
endfunction
inoremap <expr><tab> InsertTabWrapper()
inoremap <expr><s-tab> pumvisible()?"\<c-p>":"\<c-d>"
Run Code Online (Sandbox Code Playgroud)
<expr>映射.看起来更清楚更好(很多人不了解<c-r>=事情.<s-tab>像这样映射,你可以在insertmode中做unindent.