gpt4 book ai didi

c++ - 如何让 omnicppcomplete 自动关闭空参数列表?

转载 作者:搜寻专家 更新时间:2023-10-31 01:23:12 24 4
gpt4 key购买 nike

是否可以让 Vim 的 omnicppcomplete 自动关闭不接受任何参数的函数或方法的参数列表?

例如,假设 v 是一个 STL vector ,当自动完成 v.clear() 时,我们最终得到:

v.clear(

如果能自动添加右括号就好了。这可能吗?

最佳答案

看起来应该可以:我不确定我是否有最新版本的 omnicppcomplete 脚本,但是在我的 autoload/omni/cpp/complete.vim 中,有一个名为 s:ExtendTagItemToPopupItem 的函数。在这个函数中,有:

" Formating information for the preview window
if index(['f', 'p'], tagItem.kind[0])>=0
let szItemWord .= '('
if g:OmniCpp_ShowPrototypeInAbbr && has_key(tagItem, 'signature')
let szAbbr .= tagItem.signature
else
let szAbbr .= '('
endif
endif

在行(#165 在我的版本中)let szItemWord .= '(' 之后,添加:

    if (has_key(tagItem, 'signature') == 0) || (tagItem['signature'] =~ '()')
let szItemWord .= ')'
endif

应该 可以解决这个问题(尽管我不常使用 C++,所以我没有广泛测试它)。它基本上检查函数的“签名”是否包含“()”而不是(例如)“(int *major, int *minor)”。如果括号是空的,它会添加一个右括号。

为了完整性,可以通过将 '()' 更改为 '(\s*\(void\)\?\s*)' 来改进它:this将检查“()”、“( )”、“(void)”、“( void )”等

关于c++ - 如何让 omnicppcomplete 自动关闭空参数列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1815542/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com