问题
我想让 vim keyword 完成菜单显示它向我建议的函数的参数。 我希望它看起来像这样:
这是使用 ctags 的全方位补全,它很棒但速度很慢,所以我不能将它用于大型标签文件。
问题
这是我当前使用 ctags 完成关键字的样子(set complete=t
):
我的研究
我试图查看 vim 的文档 (ins-completion, 'complete', 'completeopt', 'completefunc', 'omnifunc', 'ft-c-omni'
) 但唯一的方法为了实现我的目标,似乎要编写我自己的 'completefunc'
我不想做的事情。
但是我发现我可以获得一个显示我想要的信息的弹出菜单,但是使用我当前的配置(set completeopt=menuone,noinsert,popup
)它只显示在 omni completion 中,还是太慢了。
最佳答案
我没有设法让 vim 关键字完成按照我想要的方式运行,所以我浏览了 vim 文档 (:h tag, popup, popup_atcursor
),我得出的结论是创建我自己的简单弹出窗口应该可以解决问题。
代码
" get the parameters of a function and put it in a popup using ctags
func GetFuncParamsFromTag()
silent write
" jump to tag under cursor
silent execute "normal \<c-]>"
" if there is '(' on the same line, it may be a function
if search('(', "n") == winsaveview()["lnum"]
" yank the function's name and parameters
silent execute "normal v/)\<cr>y\<c-t>"
" remove any previously present popup
call popup_clear()
" make the popup spawn above/below the cursor
call popup_atcursor(getreg('0'), #{moved: [0, 80], highlight: 'WildMenu'})
endif
endfunc
nnoremap <silent> <leader>? :call GetFuncParamsFromTag()<cr>
预览
看起来像这样:
您只需按 <leader>?
在普通模式下的函数名称上,您会看到一个漂亮的小弹出窗口,仅显示函数的原型(prototype)。
编辑:
当我使用 vim 完成时,我找到了一个解决方法来让它工作。
autocmd CompleteDone * execute "normal ^,?" | call feedkeys("\<esc>:autocmd! InsertLeave * ++once call popup_clear()\<cr>A")
只要你完成一个单词,这个自动命令就会弹出一个窗口,所以如果你输入
myImcompleteFunctionTag<c-]><c-y>
它将完成您的标记,然后打开弹出窗口,并在行尾让您处于插入模式。
autocmd 的其余部分会在您下次离开插入模式时关闭弹出窗口。
关于vim - 使vim关键字补全菜单显示函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63299580/