vim 在我输入时更新完整的弹出窗口
vim update complete popup as I type
我正在尝试在 vim
中使用 complete()
以便它也读取值。
例如,来自 vim
的 complete()
示例,
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
如果我键入 <F5>
,我将弹出所有月份。现在,我想要的是,如果我输入 "J",只会显示一月、六月和七月,"Ju" 会显示六月和七月,依此类推。
我阅读了 vim-doc
,并尝试了 complete_check
,但事实并非如此。
此外,我曾尝试在 vimdoc
中使用 omnicomplete 示例 E839
,但我无法正确调用它,总是得到无效参数。
请建议我在键入时完成菜单的首选方法,以及如何使用它。
首先,该示例完成不考虑已经键入的基数,因为它总是在光标位置开始完成(通过 col('.')
)。
其次,要获得 "refine list as you type" 行为,您需要进行以下设置:
:set completeopt+=longest
不幸的是,由于 (long known) bug,complete()
没有考虑 '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>
我正在尝试在 vim
中使用 complete()
以便它也读取值。
例如,来自 vim
的 complete()
示例,
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
如果我键入 <F5>
,我将弹出所有月份。现在,我想要的是,如果我输入 "J",只会显示一月、六月和七月,"Ju" 会显示六月和七月,依此类推。
我阅读了 vim-doc
,并尝试了 complete_check
,但事实并非如此。
此外,我曾尝试在 vimdoc
中使用 omnicomplete 示例 E839
,但我无法正确调用它,总是得到无效参数。
请建议我在键入时完成菜单的首选方法,以及如何使用它。
首先,该示例完成不考虑已经键入的基数,因为它总是在光标位置开始完成(通过 col('.')
)。
其次,要获得 "refine list as you type" 行为,您需要进行以下设置:
:set completeopt+=longest
不幸的是,由于 (long known) bug,complete()
没有考虑 '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>