【问题标题】:vim update complete popup as I typevim 在我输入时更新完成弹出窗口
【发布时间】:2016-04-17 04:51:37
【问题描述】:

我正在尝试在vim 中使用complete(),以便它也能读取该值。

例如,来自vimcomplete()例子,

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

如果我输入&lt;F5&gt;,我会弹出所有月份。现在,我想要的是,如果我输入“J”,则只显示一月、六月和七月,“Ju”将给出六月和七月,依此类推。

我阅读了vim-doc,并尝试了complete_check,但事实并非如此。

另外,我曾尝试在vimdoc 中使用omnicomplete 示例E839,但我无法正确调用它,总是得到无效的参数。

请在我输入时建议我首选的带有完成的菜单方法,以及如何使用它。

【问题讨论】:

    标签: vim omnicomplete


    【解决方案1】:

    首先,该示例补全不考虑已键入的基数,因为它总是在光标位置开始补全(通过col('.'))。

    其次,要获得“键入时优化列表”行为,您需要以下设置:

    :set completeopt+=longest
    

    不幸的是,由于(long known) bugcomplete() 不考虑'completeopt' 选项。你必须改用'completefunc',就像这个重写的例子一样:

    fun! CompleteMonths(findstart, base)
        if a:findstart
            " locate the start of the word
            let line = getline('.')
            let start = col('.') - 1
            while start > 0 && line[start - 1] =~ '\a'
                let start -= 1
            endwhile
            return start
        else
            echomsg '**** completing' a:base
            " find months matching with "a:base"
            let res = []
            for m in ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
                if m =~ '^' . a:base
                call add(res, m)
                endif
            endfor
            return res
        endif
    endfun
    inoremap <F5> <C-o>:set completefunc=CompleteMonths<CR><C-x><C-u>
    

    【讨论】:

      猜你喜欢
      • 2014-05-04
      • 2017-10-30
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      • 2011-12-03
      • 2021-11-21
      相关资源
      最近更新 更多