在vim /标签组织一般使用多个标签文件一次 [英] Using multiple tag files at once in vim / Tag organisation in general

查看:115
本文介绍了在vim /标签组织一般使用多个标签文件一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(道歉的C标记,我是做语法高亮,这更是一个VIM问题。如果有人比我更学会认为标签应该被删除,请这样做)

(Apologies for the C tag, I did it for the syntax highlighting. This is more of a vim question. If someone more learned than I thinks the tag should be removed please do so)

说我得到了这个目录结构:

Say I've got this directory structure:

Directory ~/Code/Test/     containing file1.c file2.c file4.c and Sub 
Directory ~/Code/Test/Sub/ containing file3.c

file1.c中:

file1.c:

#include <stdio.h>
#include "file2.c"
#include "Sub/file3.c"

void function1();

int main (int argc, char *argv[]) {
   function1();
   function2();
   function3();
   return 0;
}

void function1() {
   printf("1\n");
}

file2.c中:

file2.c:

#include <stdio.h>

void function2();

void function2() {
   printf("2\n");
}

子/ file3.c中:

Sub/file3.c:

#include "../file4.c"

void function3();

void function3() {
   printf("3\n");
   function4();
}

file4.c:

file4.c:

#include <stdio.h>

void function4();

void function4() {
   printf("4\n");
}

在这些文件中的任何一个应当有可能跳到它从其他文件使用的功能的定义。因此,例如,文件1应该能够传达给文件2跳,文件1应该可以跳下目录FILE3,file3的应能跳起来的目录FILE4,这里的踢球; 所有的文件应该能够跳到printf的定义。我不应该为C库实现标签复制到测试目录中,为了做到这一点。

In any one of those files it should be possible to jump to the definition of the functions it uses from the other files. So for example, file1 should be able to jump across to file2, file1 should be able to jump down a directory to file3, file3 should be able to jump up a directory to file4, and here's the kicker; all of the files should be able to jump to the definition of printf. I also shouldn't have to copy the tags for the c library implementation into the Test directory in order to do this.

我不知道我怎么会去这样做。我真的不热衷于单片标签文件。拥有一个VIM范围的标记文件使我反感。每个目录下的标签文件,惹恼了我。每个项目的标签文件是可以忍受的。但我真的很想为每源文件中的标签文件,然后一个方法来指定哪些标签文件的vim应该是指

I'm wondering how I could go about doing this. I'm really not keen on monolithic tags files. Having a vim-wide tags file horrifies me. A tags file per directory annoys me. A tags file per project is bearable. But what I'd really like is a tags file per source file, and then a way to specify which tags files vim should be referring to.

在理想情况下,我想能够公正CTRL-]上的任何东西,并有VIM跳转到基于什么在范围内的正确定义,就像视觉工作室。我开始怀疑这不能做,如果是(通过插件的组合),这将是非常缓慢的,这实在是烦人,因为我是完全的Vim可以做任何事情,你新奇的IDE可以做的便车了几个星期那里。是的,它绝对是最强大的文本编辑器,我已经遇到,但作为一个IDE这是非常糙米。当我用转到定义命令,我预计将要采取的正确定义它是否是一个局部变量,在不同的文件中,在一个标准库等的Vim到目前为止已经给了我欢闹的结果,如从跨跳java的文件交流文件。你必须使用一个单独的命令跳转到一个局部变量的定义...什么? (如果有一个原因,这背后我有兴趣知道)

Ideally I'd like to be able to just ctrl-] on anything and have vim jump to the correct definition based on what's in scope, just like visual studio. I'm beginning to suspect this can't be done, and if it is (via some combination of plugins) it would be extremely slow, which is really annoying because I was totally on the "Vim can do anything your newfangled IDEs can do" bandwagon for a couple of weeks there. Yes it's definitely the most powerful text editor I've come across, but as an IDE it's extremely unpolished. When I use the "Go to definition" command I expect to be taken to the correct definition whether it's a local variable, in a different file, in a standard library etc. Vim so far has given me hilarious results such as jumping across from a java file to a c file. And you have to use a separate command to jump to the definition of a local variable... What? (If there's a reason behind this I'd be interested in knowing)

我知道wacking 组标签=的。/标签在我的.vimrc,这就是我到目前为止已经完成。但是,这不会规模,如果我的东西大量的链接单独的程序集和源文件从单独的项目合作。

I'm aware of wacking set tags=./tags in my .vimrc and that's what I've done so far. But this won't scale if I work on something massive that links separate assemblies and source files from separate projects together.

(为了公平起见VIM时,Visual Studio不会让你跳跨组件必须要么找到的定义,但它至少有识趣地成为了一个头文件,从中可以装载组件和导航实际的源$ C ​​$ C你正在寻找)

(To be fair to vim, visual studio doesn't let you jump across assemblies to find definitions either, but it does at least have the good grace to serve up a header file from which you can "load assembly" and navigate to the actual source code you're looking for)

推荐答案

首先第一件事情: Vim中从来没有,现在不是,将来可能永远是一个IDE合适的替代谁做你认为应该出手,你也应该被枪杀相信这样的无稽之谈。

First things first: Vim has never been, is not and will probably never be a proper alternative to an IDE. Whoever made you believe that should be shot and you should be shot too for believing such nonsense.

我只是半开玩笑的。

Vim的是一个非常强大的面向对象编程的文本编辑器,但一个简单的事实,你需要运行一个愚蠢的外部code索引得到一个愚蠢的跳转到或别的code索引再弄哑跳转到使用应该是一个暗示,Vim不是现实进行比较的IDE。提示: I 在IDE中的意思是集成和电子的意思是环境。既然你不能得到适当的整合的和将pssed考虑的Vim作为的环境硬$ P $ 的,有没有IDE,在这里。只有许多插件以不同的方式做不同的事情,最重要的一个文本编辑器,无严重办法的了解的您code这是一种血统的IDE的#1功能。

Vim is a very powerful programming-oriented text editor but the simple fact that you need to run a dumb external code indexer to get a dumb "jump to definition" or another code indexer to get another dumb "jump to usage" should be a hint that Vim can't realistically be compared to an IDE. Hint: the I in IDE means "Integrated" and the E means "Environment". Since you can't get proper integration and would be hard-pressed to consider Vim as an environment, there's no IDE, here. Only a text editor with many plugins doing different things in different ways and, above all, no serious way to understand your code which is the #1 feature of a descent IDE.

许多用户/博客声称,他们使用的是Vim的作为IDE,或者说你可以,也把Vim的变成一个Python或任何IDE,但事实是,Vim的缺乏所有的低层次的功能,会做出这样的事可能。你可以把它变成东西看起来的像一个IDE,如果你以某种方式能够相信自己的谎言,但它可能永远不会的一个IDE。

Many users/bloggers claim they are using "Vim as an IDE" or that you could, too, turn Vim into a Python or whatever IDE but the truth is that Vim lacks all the low-level features that would make such a thing possible. You can turn it into something that looks like an IDE, if you are somehow able to believe in your own lies, but it will probably never be an IDE.

无论...


  • 默认行为&LT(它不能在您的配置进行修改),C - &GT; :标签富是跳转到你的标签先打文件(S)。无论是Vim的也不Ctags的了解范围。 TS富或 G] :在最好的情况,您可以从中选择正确的标记(列表进行治疗),但是这就是你能走多远。

  • The default behavior (which can't be altered in your configuration) of <C-]> or :tag foo is to jump to the first hit in your tags file(s). Neither Vim nor Ctags know about scope. At best, you can be treated with a list from which to choose the correct tag (:ts foo or g]) but that's how far you can go.

根据你一起工作的语言,Cscope的可能会在索引你的code更好,但总的原则是一样的用Ctags的。 Cscope的提供了一个跳转到使用功能,因此它可能是值得只是因为它的开关。

Depending on the languages you work with, Cscope might be better at indexing your code but the general principle is the same as with Ctags. Cscope offers a "jump to usage" feature so it might be worth switching just for it.

制作使用可以是一个痛苦确保正确标记文件(S)和DOC是令人惊讶的不是在这方面非常有帮助。有一堆设计,使其更简单,你可以尝试插件,EasyTags浮现在脑海。

Making sure the correct tags file(s) are used can be a pain and the doc is surprisingly not very helpful in that regard. There are a bunch of plugins designed to make it simpler that you could try, EasyTags comes to mind.

我承认我不工作在非常大的项目,甚至不是在C所以也许这将似乎不是很有用,但是这条线在我的的〜/ .vimrc 使得与标签工作更容易:

I admit I don't work on very large projects and not even in C so maybe this won't seem useful but this line in my ~/.vimrc makes working with tags easier:

set tags=./tags;/,tags;/

通过此设置,Vim的查找和最多(非递归),直到 / 标记文件。这样做的主要的一点是要有一个标记文件在我的每一个项目,可以从该项目中的每个文件中使用的根甚至无需告知Vim在哪里寻找一个标记文件。

With this setting, Vim looks up and up (non-recursively) until / for tags files. The main point of this is to have a single tags file at the root of each of my projects that can be used from every file in that project without ever needing to tell Vim where to look for a tags file.

要对付你的Java / C mixups可以把你的项目进入特定语言的目录中的一种方式:

One way to deal with your Java/C mixups could be to put your projects into language-specific directories:

C/
  c.tags
  proj1/
    tags
    …
  proj2/
    tags
    …
Java/
  j.tags
  proj3/
    tags
    …
  proj4/
    tags
    …


,把你的全球标记在他们的根以及具体项目的标签文件的文件各自项目的根目录。

and put you "global" tags files at their root as well as project-specific tags files at the root of their respective projects.

要处理这个问题的另一种方法可以指导的Vim根据文件类型为加载特定的标记文件:

Another way to deal with that issue could be to instruct Vim to load specific tags files depending on the filetype:

    autocmd FileType c setlocal tags=/path/to/your/global/c/tags,./tags;/,tags;/

这篇关于在vim /标签组织一般使用多个标签文件一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆