仅在当前文件中搜索标签

发布于 2024-12-23 02:34:36 字数 446 浏览 4 评论 0 原文

我正在使用“:ta”跳转到一个方法。
例如,我有两个名为 A.javaB.java 的类。它们都有一个 foo() 方法,B.java 有另一个名为 fooBar() 的方法。然后我打开 A.java 并输入 :ta foo 然后按 TAB 然后我会得到两个完成: foofooBar。但我现在想跳转的只是当前文件中的标签,我不喜欢显示其他文件中的标签。

And i found tagslist does very good in this job. So if i can use the tag generated by taglist to search from, it will be very nice.

I am using ":ta " to jump to a method.
For example i got two classes named A.java and B.java. They both have a foo() method and B.java have another method called fooBar(). Then i open A.java and input :ta foo then press TAB then i will got two completion : foo and fooBar. But what i want to jump now is just tag in current file, i don't like tag in other file to display.

And i found tagslist does very good in this job. So if i can use the tag generated by taglist to search from, it will be very nice.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

落墨 2024-12-30 02:34:36

根据您调用方法的次数,几个 * 可能就足够了。

在不使用标签的情况下,可以使用 gd 转到光标下方法的本地声明。我通常倾向于选择技术含量最低的解决方案,所以我会选择这个。

但是,ctags 还能够仅为单个文件或任意选择的文件生成标签。只需几个步骤即可完成,但它绝对不像您习惯的那样简单...

  1. 使用您要扫描的文件的名称创建一个文件。假设它名为 files.txt 并且位于工作目录的根目录下。

    使用

  2. 使用 -L 参数生成 tags 文件:ctags -L files.txt

此时,您应该有一个 tags 文件,仅包含步骤 1 中指定的文件中存在的标签。

为整个项目和单个项目生成不同的 tags 文件文件可能有用,在这里。生成一个以当前文件命名的 tags 文件并使其成为唯一的 tags 源的简短脚本可能会使整个事情变得更容易。

编辑

实际上,TagList和TagBar不会生成标签文件。它们运行的​​ ctags 命令的输出在内部使用,并使用各种正则表达式进行解析,以按范围或文件名或其他内容进行过滤。

Depending on how many times you call your methods a couple of * may be enough.

Without using tags, gd can be used to go to the local declaration of the method under your cursor. I tend to choose the most low-tech solution usually, so I would go with this one.

But ctags is also able to generate tags for a single file only or for an arbitrary selection of files. It can be done in a few steps but it's definetely not as straightforward as what you are accustomed to do…

  1. Create a file with the name(s) of the file(s) you want to scan. Let's say it's called files.txt and it's located at the root of your working directory.

  2. Generate your tags file using the -L <file> argument: ctags -L files.txt.

At this point you should have a tags file containing only the tags present in the file(s) specified at step 1.

Generating different tags files for the whole project and for single files may be useful, here. A short script generating a tags file named after the current file and making it the sole tags source may make the whole thing easier.

EDIT

Actually, TagList and TagBar don't generate tags files. The output of the ctags <options> command they run is used internally and parsed with all kinds of regexp to filter by scope or filename or whatever.

傲世九天 2024-12-30 02:34:36

不幸的是,这无法使用 ctags 来完成。 Ctags 不尊重上下文,它是所有可能的“功能”的纯粹列表。尝试使用编辑器(例如 vim)打开标签文件,您将看到它只是一个“函数”列表(对于 Java,它们是“方法”)。示例:

getDesc src/com/redhat/rhn/internal/doclet/Handler.java /^    public String getDesc() {$/;" m   class:Handler
getDoc  src/com/redhat/rhn/internal/doclet/ApiCall.java /^    public String getDoc() {$/;"  m   class:ApiCall

Vim 只是“按原样”搜索文件,而不提供任何上下文 - 它只是搜索“函数”。它能够搜索文件、类、方法、枚举等。标签格式在这里有更详细的描述:http: //ctags.sourceforge.net/FORMAT

在 Vim 中你几乎没有什么可能性。有几个插件可以为 Vim 提供一些上下文敏感性,但您不能使用标签。 Vim 本身有一个名为 OmniComplete 的功能,并且很少有专门用于 Java 的插件。然后您可以使用Ctrl-X Ctrl-O开始补全。我建议您将其映射到不同的键(如果您愿意,可以使用 Ctrl-空格键)。有关 Java OmniComplete 插件的更多信息,请访问:

Vimomnicompletion for Java

Eclim (http://eclim.org/) 非常全面,但设置起来很困难(您需要在后台运行 Eclipse)。 JDE 脚本更简单,也更强大 (http://www.vim.org/脚本/script.php?script_id=1213)。请注意 IntelliJ IDEA 社区版(免费)还有一个非常好的 Vim 插件,可以免费使用。但我理解你 - Vim 就是 Vim。

祝你好运!

Unfortunately this cannot be done using ctags. Ctags does not respect context, it is a pure list of all possible "functions". Try to open a tag file with an editor (e.g. vim) and you will see it is just a list of "functions" (in case of Java they are "methods"). Example:

getDesc src/com/redhat/rhn/internal/doclet/Handler.java /^    public String getDesc() {$/;" m   class:Handler
getDoc  src/com/redhat/rhn/internal/doclet/ApiCall.java /^    public String getDoc() {$/;"  m   class:ApiCall

Vim just search the file "as is" without giving it any context - it just search for a "function". It is able to search for files, classes, methods, enums etc. Tags format is described in more detail here: http://ctags.sourceforge.net/FORMAT

In Vim you have few possibilities. There are several plugins that gives Vim some context sensitivity, but you cannot use tags for that. Vim itself has a feature called OmniComplete and there are few plugins dedicated for Java. Then you can use Ctrl-X Ctrl-O to start a completition. I recommend you to map this to a different key (maybe Ctrl-Space if you like). More info about Java OmniComplete plugins here:

Vim omnicompletion for Java

Eclim (http://eclim.org/) is very comperhensive, but difficult to setup (you need to run Eclipse in the background). JDE script is easier and also robust (http://www.vim.org/scripts/script.php?script_id=1213). And please note IntelliJ IDEA Community Edition (free) also has a very nice Vim plugin that is free to use. But I understand you - Vim is Vim.

Good luck!

岛徒 2024-12-30 02:34:36

不完全是您问题的答案,但似乎没有办法完全满足您的需要,因此,我建议您执行以下操作:对于 Vim 中的 Java 开发,请尝试 eclim

该工具可帮助您使用您最喜欢的文本编辑器 Vim 以及 Eclipse (IDE) 的功能。
我找不到 :ta 制表符补全的类似物,但我知道 g] 的智能类似物:这是一个命令 :JavaSearchContext。您可以将其映射到某些东西。

例如,如果您有两个类 AB,并且每个类中都有方法 foo(),则 g] 每次你想跳转到 foo() 时都会询问你,但 :JavaSearchContext 总是会跳转到 foo()< 的正确声明/代码>。

当然,还有很多其他功能。

Not exactly an answer to your question, but it seems like there's no way to do exactly what you need, so, i would recommend you the following: for your Java development in Vim, try eclim.

This tool helps you to use your favorite text editor Vim with power of an Eclipse (IDE).
I can't find analogue for tab-completion of :ta, but i know a smart analogue for g] : this is a command :JavaSearchContext. You can map it to something.

For example, if you have two classes A and B, and you have method foo() in each class, then g] will ask you every time you want to jump to foo(), but :JavaSearchContext will always jump to the proper declaration of foo().

Of course, there are many other features.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文