代码之家  ›  专栏  ›  技术社区  ›  Ton van den Heuvel

如何让omnicpComplete自动关闭空参数列表?

  •  2
  • Ton van den Heuvel  · 技术社区  · 15 年前

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

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

    v.clear(
    

    最好是自动添加右括号。这有可能吗?

    2 回复  |  直到 14 年前
        1
  •  3
  •   DrAl    15 年前

    看起来应该是可能的:我不确定是否有最新版本的全包脚本,但在我的 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*)' 完整性:这将检查“ () “,” ( ) “,” (void) “,” ( void ) “等等。

        2
  •  1
  •   mattepiu    14 年前

    我只是替换了165行:

    let szItemWord .= '('
    

    具有

    let szItemWord .= tagItem['signature']
    

    这样,我在代码中得到了整个原型,而不是函数名,然后我逐个替换参数。

    推荐文章