vim中的omnicomplete与shift选项卡不工作



我试图让vim允许我用tab键在自动完成弹出列表中循环。它适用于tab,但不适用于s-tab(shift tab)。在应用C-P 之前,移位选项卡似乎以某种方式取消了自动完成菜单

有人有什么想法吗?

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>

对于<s-tab>映射,您错过了<c-r>之后的等号"="。

然而,我建议这样做:

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>,您可以在插入模式下执行unident

最新更新