vim 自定义弹出菜单

Hea*_*ray 7 vim autocomplete

如何创建自定义完成弹出菜单。

我希望能够开始输入字符串的一部分,然后按自定义组合键以弹出特定字符串组的弹出完成。

我已经完成了全方位设置,不想添加到该列表中。

例如,我有一个列表:
spo
spe
spa

我希望能够输入 sp 然后按 ctrl+> 并为该特定列表显示一个完成框。

Hea*_*ray 6

  inoremap <F5> <C-R>=ListMonths()<CR>

    func! ListMonths()
      call complete(col('.'), ['January', 'February', 'March',
            \ 'April', 'May', 'June', 'July', 'August', 'September',
            \ 'October', 'November', 'December'])
      return ''
    endfunc
Run Code Online (Sandbox Code Playgroud)

找到了!隐藏在他们试图告诉我们的魔法书里是文档 =)

======================== 我的最终脚本类似于

inoremap <F5> <C-R>=CustomComplete()<CR>

        func! CustomComplete()
                echom 'move to start of last word'
                normal b
                echom 'select word under cursor'
                let b:word = expand('<cword>')
                echom '->'.b:word.'<-'
                echom 'save position'
                let b:position = col('.')
                echom '->'.b:position.'<-'
                normal e
                normal l
                echom 'move to end of word'     

                let b:list = ["spoogle","spangle","frizzle"]
                let b:matches = []


                echom 'begin checking for completion'
                for item in b:list
                echom 'checking '
                echom '->'.item.'<-'      
                        if(match(item,'^'.b:word)==0)
                        echom 'adding to matches'
                        echom '->'.item.'<-'      
                        call add(b:matches,item)
                        endif
                endfor
                call complete(b:position, b:matches)
                return ''
        endfunc
Run Code Online (Sandbox Code Playgroud)