本文介绍了Vim:如何去声明(类、方法、函数、变量等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在处理一个使用许多类、方法、函数、变量等的文件.是否可以转到所有这些的声明?请注意,其中一些声明在同一个文件中,而另一些在其他文件中(可能无法打开,您不知道声明在哪里,但它们确实存在).如果声明在目录中的上一级会发生什么?如果是低一级呢?

Right now I am working on a file which uses many classes, methods, functions, variables, etc. Is it possible to go to the declaration of all of them? Please, take into account that some of those declarations are in the same file but others are in other files (which may not be opened and you do not know where the declarations are but they do exist). What would happen if the declaration is one level up in the directory? and what about if it is one level down?

这是根据我们所讨论的编程语言以不同的方式完成的,还是无论语言如何,查找声明的过程都是相同的?

Is this done in a different way according to the programming language we are talking about or the procedure to find the declarations is the same regardless of the language?

我一直在阅读,似乎解决方案与标签有关.但是,我想知道如何(逐步)实现这一点,特别是考虑到我们在某些情况下正在谈论其他文件中的定义.

I have been reading and it seems the solution is related to tags. However, I would like to know how this can be achieved (step by step), especially taking into account that we are talking, in some cases, of definitions in other files.

我知道这可以通过 IDE 完成,但我想知道使用 vim 可以实现多少不同.

I know this can be done with IDEs but I would like to know how much different this can be achieved with vim.

我只有全新安装的 Vim.我还没有安装任何插件,但如果有必要,我愿意这样做.也许这可以在没有和使用插件的情况下完成.

I only have a fresh install of Vim. I have not installed any plugins yet but willing to do if it is necessary. Perhaps this can be done without and with plugins.

提前致谢!

推荐答案

设置 标签 并不难,尽管(与 Vim 中的大多数东西一样)它不像 IDE 那样自动.

Setting up tags is not so difficult, though (as most things in Vim) it's not as automatic compared to IDEs.

  1. 首先,您需要 ctags 工具.今天最常见的是 Exuberant Ctags,可以在 ctags.sourceforge.net 找到.
  2. 接下来,您需要为项目中的所有文件创建一个tags 数据库(文件名tags).这通常通过从项目根目录运行 ctags -R . 来完成(也可以在 Vim 中通过 :!ctags ... 运行).Exuberant Ctags 支持41 种语言,您甚至可以通过正则表达式对其进行扩展.
  3. 最后,需要配置 Vim 以获取 tags 数据库.使用:set tags=./tags;,它将在文件目录中向上搜索到根目录.如果您有某些全局包含目录,则可以添加这些目录.
  4. 这样,你就可以开始使用 Vim 的标签功能了,比如 <C-]>:tag.
  1. First, you need the ctags tool. The most common today is Exuberant Ctags, found at ctags.sourceforge.net.
  2. Next, you need to create a tags database (a file names tags) for all the files in your project(s). This is usually done by running ctags -R . from your project root (also from within Vim via :!ctags ...). Exuberant Ctags support 41 languages, and you can even extend it via regular expressions.
  3. Finally, Vim needs to be configured to pick up the tags database. With :set tags=./tags;, it will search in the file's directory upwards to the root directory. If you have certain global include directories, you can add those.
  4. With that, you can start using Vim's tag functionality like <C-]> and :tag.

您需要定期更新标签数据库;有一些插件(比如 easytags.vim)可以自动为你.

You need to periodically update the tags database; there are plugins (like easytags.vim) that can do that automatically for you.

这篇关于Vim:如何去声明(类、方法、函数、变量等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 08:11