gpt4 book ai didi

C 的 Vim 函数提示

转载 作者:行者123 更新时间:2023-12-04 02:15:39 28 4
gpt4 key购买 nike

我正在尝试实现一些简单的东西,通常称为“功能提示”。例如,基于 scintilla 的编辑器有它:

enter image description here

你输入一个名字,然后得到原型(prototype)。在 vim 中存在一些问题:

  • 您必须重建 ctags 以使其保持最新
  • 您不能在 ( 之后键入 C-X C-O ,你只会得到“找不到模式”
  • 在普通模式下不能输入 C-X C-O,光标只会跳动
  • 你会在顶部看到恼人的预览窗口

  • 我尝试了一些插件;他们中的大多数人把事情搞得更糟[^1]。谁能推荐一个简单的方法来做到这一点?一个包含函数原型(prototype)的简单矩形,仅此而已。

    [^1] 这些插件中的一些是多么愚蠢,真是令人 NumPy 。一个插件(我不会提及)实际上包含在 .vim 文件中,其中包含来自 libc 的函数列表。

    最佳答案

    ctags因为自动完成是一团糟。我建议您尝试使用基于编译器的插件,例如 clang-completegcc-sense (这个没试过)。优点是:

  • 更准确,因为他们所做的几乎是编译
  • 编译错误在源代码上动态标记

  • You have to rebuild the ctags to keep it up to date



    您不需要处理 ctags(尽管它们仍然可以用来跳转)

    You can't type C-X C-O after the (, you'll just get "Pattern not found"



    你会期待什么?

    You can't type C-X C-O in normal mode, the cursor will just jump around



    如果您认为这是一个常见错误,您可以随时重新映射该序列(例如 nnoremap <C-x><C-o> a<C-x><C-o> )

    You get the annoying preview window at the top



    您可以通过删除 preview 来禁用它。来自 completeopt选项。见 :help completeopt
    我正在使用以下设置:

    here
  • clang-complete完成
  • supertab填写 tab关键
  • ultisnips用于函数签名占位符。 (也适用于 snipmate )

  • 和一些 vimrc 设置:
    set pumheight=10             " so the complete menu doesn't get too big
    set completeopt=menu,longest " menu, menuone, longest and preview
    let g:SuperTabDefaultCompletionType='context'
    let g:clang_complete_auto=0 " I can start the autocompletion myself, thanks..
    let g:clang_snippets=1 " use a snippet engine for placeholders
    let g:clang_snippets_engine='ultisnips'
    let g:clang_auto_select=2 " automatically select and insert the first match

    享受!

    关于C 的 Vim 函数提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11300788/

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