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

jon*_*naz 2 vim omnicomplete

我试图让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)

tun*_*ngd 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>"
Run Code Online (Sandbox Code Playgroud)
  1. 使用<expr>映射.看起来更清楚更好(很多人不了解<c-r>=事情.
  2. <s-tab>像这样映射,你可以在insertmode中做unindent.

  • 好像有人对您的代码印象深刻:http://moviecode.tumblr.com/post/76605632708/the-intro-sequence-of-the-anime-time-of-eve (3认同)
  • 我的天啊!我在RSS提要上看了帖子,但没有意识到这是我的回答. (2认同)