在移动标签不工作的vim omnicomplete?

时间:2012-03-17 16:11:31

标签: vim omnicomplete

我试图让vim允许我使用tab键遍历自动完成弹出列表。它适用于制表符,但不适用于s-tab(shift-tab)。 在应用C-P

之前,似乎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>

1 个答案:

答案 0 :(得分:6)

您在<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>"
  1. 使用<expr>映射。看起来更清楚(很多人不了解<c-r>=件事。
  2. 像这样映射<s-tab>,您可以在insertmode中执行unindent。
相关问题