pythonrubyvimctagsgnu-global

Differences between several vim tags plugin


I have two questions actually.

First, as far as I know, there are two tags tools:

  1. Ctags
  2. GNU Global a.k.a. gtags

I'm wondering which one is more suitable if my daily works are concentrated on Ruby, Rails, JavaScript, and Python. Namely, dynamic languages. I've googled a little bit, and it seems gtags is somehow equivalent to ctags + cscope?

Second, as for ctags, there are some vim plugins:

  1. vim-tags: It can generate tags files in Vim through the command :TagsGenerate.
  2. tagbar: A famous plugin. It seems it can generate tags on-the-fly.
  3. vim-easytags: Seems like vim-tags, but with more features.

I'm wondering

  1. Is there any overlap among these plugins?
  2. If there are overlaps, how to integrate them or how to choose which one to use?

I know the it is not good to have two questions in one SO post, but I think these two questions are highly related as they are essential to the Vim+Tags combination. Hope this question can serve as a foundation or tutorial for people who want to use tags but not familiar with it just like me. (I can't find a "modern" tutorial for vim+ctags, most post on the internet are out-dated IMO)

Thanks.

Update:

Basically, I want to be able to

  1. Jump to the declaration of certain function
  2. Jump to the usage of certain function
  3. Make autocompletion more smarter. I mean, if I have

    class Obj
      def m1
        puts "hello"
      end
    end
    

    then I want autocompletion to show m1 when I type obj = Obj.new; obj.. As far as I know, YouCompleteMe can consume ctags' file, but I fail to set it up even I follow the instruction.

To be honestly, I don't really know what ctags can do or can offer. So please feel free to suggest more useful features. Thanks!


Solution

  • You can forget GNU GLOBAL right now because — last time I checked — it didn't support JavaScript at all. I don't know about Ruby and Python but it shouldn't be too hard for you to test it out.

    Ctags works with JavaScript (and the others) but it doesn't like the "modern" way of writing JavaScript (inline callbacks, abused literal objects, self-invoking functions…). You can help it a little by adding the following lines to your ~/.ctags file:

    --langmap=javascript:.js
    --regex-javascript=/([A-Za-z0-9._$()]+)[ \t]*[:=][ \t]*function[ \t]*\(/\1/F,function,functions/
    --regex-javascript=/function[ \t]*([A-Za-z0-9._$()]+)[ \t]*\(/\1/F,function,functions/
    --regex-javascript=/([A-Za-z0-9._$]+)[ \t]*=[ \t]*\{/\1/o,object,objects/
    --regex-javascript=/^[ \t]*([A-Za-z0-9._$]+)[ \t]*[:][ \t]*[^\{]/\1/p,property,properties/
    --regex-javascript=/^[ \t]+var[ \t]*([A-Za-z0-9._$]+)[ \t]*=[ \t]*[\d"'\[]/\1/v,variable,variables/
    

    These work for me but my JavaScript is admittedly a bit "old school". Note that ctags is limited to "definitions/declarations".

    There are also language-specific variants of ctags that usually give more sensible results like jsctags (JavaScript) or ripper-tags (Ruby)

    Cscope, on the other hand, does "usage" and works for all your languages. Setting it up is a bit more involved than setting up ctags ad its usage is also a bit more complex but that's quite logical, given its features.

    One "issue" you might have with cscope is that there are not many plugins written around it compared to ctags. That's a limitation worth considering.

    As for the plugins you listed…

    1. Yes, there's overlap between #1 and #3. #2 doesn't generate or use a tags file.
    2. Try them, read their doc and decide for yourself.

    You didn't even tell us how you wanted to use that feature? What are you after? tags generation? Jump to usage? Jump to declaration? An IDE-like "class explorer"? All of it?

    edit

    Let me address your comment and your edit:

    1. Both ctags and cscope allow you to "jump to declaration" of an arbitrary symbol or (via custom mappings and settings for cscope) of the symbol under your cursor.

    2. Only cscope allows you to "jump to usage".

    3. Ctags being itself a little dumb and you using highly dynamic languages make ctags a bit useless for completion purpose. Some languages have better support than others, though, so you may find some helpful third party plugins like jedi-vim or Tern for Vim.

    4. TagList and TagBar don't generate a tags file but they run do run ctags and consume its output. They just don't write it to disk. So yeah, you can use those plugins to "jump to delaration" but they are still isolated from Vim's built-in ctags support which can lead to issues.

    See :help ctags and :help cscope to get a feeling of what they can do.