gpt4 book ai didi

php - Vim:将 omnicomplete 显示的方法限制为 ctags 中存在的方法

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:48:53 25 4
gpt4 key购买 nike

如果 $bar 是此类的一个实例并且我输入

$bar->ctrlxctrlo

我得到一个弹出窗口,其中包含许多方法(内置方法)以及我的类中的方法并出现在 ctags 列表中。如何避免显示所有这些外部方法并只保留我的类中定义的方法?

最佳答案

我确定您已经看过 VIM 文档 (:help ft-c-omni):

When using CTRL-X CTRL-O after a name without any "." or "->" it is completed from the tags file directly. This works for any identifier, also function names. If you want to complete a local variable name, which does not appear in the tags file, use CTRL-P instead.

When using CTRL-X CTRL-O after something that has "." or "->" Vim will attempt to recognize the type of the variable and figure out what members it has. This means only members valid for the variable will be listed.

When a member name already was complete, CTRL-X CTRL-O will add a "." or "->" for composite types.

如果我没看错,内置功能充其量只会允许您使用 CTRL-P 并匹配局部变量名称,从而完全绕过 TAGS 文件。

您真正想要的是一个特定于您当前正在处理的翻译单元的 TAGS 文件(头文件/cpp 文件)。如果我试图解决这个问题,我将执行以下步骤:

  1. 创建一个脚本(或者更好的是,合并到 makefile 中)自动创建翻译单元特定的 TAG 文件。
  2. 在 vim 中创建一个命令,卸载现有的 TAGS 文件,重新加载文件特定的 TAGS 文件,并执行常规的 CTRL-X CTRL-O omni-completion。如有必要,恢复为原始 TAGS。

此外,在我看来,您可能希望能够直接从 VIM 调用 #1 的脚本,因为您会在编码时频繁更改当前翻译单元。

我希望这能让您朝着正确的方向开始,我很乐意看到/帮助您实现=)。

关于php - Vim:将 omnicomplete 显示的方法限制为 ctags 中存在的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2968557/

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