Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ctags, jsctags/doctorjs, Tagbar step by step

I need help on setting up ctags, jsctags, and tagbar so I can have a workable Javascript editing envrionment. I got everything installed but couldn't get an idea how ctags and jsctags work together so I don't know how to configure properly. I have done quite a bit Google around but the information is pretty broken and lacks consistency. I got an error similar to this post, ctags and tagbar configuration are out of sync. I'm on OS X mountain lion and iterm2.

Any help would be greatly appreciated. A step by step instructions would be excellent.

Thx.

like image 639
1001b Avatar asked Mar 15 '13 06:03

1001b


1 Answers

First, you have to understand that jsctags and ctags will probably never be in sync. Even if you have only a simple function, both programs may output slightly different informations. Thus it is advised to use one or the other but not both.

Second, AFAIK, TagBar doesn't need to be configured to use jsctags instead of ctags. If you are doing JavaScript it will simply default to jsctags if it's available. TagBar shouldn't complain if you have a working jsctags.

Third, for its own tag-related functionalities (:tag, :tselect, <C-]>, etc.), Vim only relies on the presence of one or more physical tags files. Whether those files are generated by ctags, jsctags or whatevertags is not a concern as long as they are generated correctly.

And now we arrive at the fourth point which is where the pain really is: neither Tagbar nor its older cousin TagList actually use a physical tags file. They tap ctags or jsctags directly without even trying to use or update any existing tags file. Because of that, and the fact that TagBar only deals with the current buffer, your own physical tags file (and thus Vim's tag-related functionalities) and TagBar are almost guaranteed to be out of sync. Even if you use the same indexer.

So… I'd advise you to use either ctags or jsctags and forget anything about syncing TagBar's and Vim's tags-related stuff as both things are completely separate:

  • Use TagBar to understand/navigate in your current buffer.

  • Use Vim's tag-related functionalities to move around your project.


Random thoughts…

  • For Vim to locate your tags file(s) easily, you should put this line in your ~/.vimrc:

    set tags=./tags,tags;/
    

    ./tags means "look for a tags file in the directory of the current file", tags means "look for a tags file in the working directory", ;/ means "keep looking up and up until you reach /".

  • The TagBar wiki talks about a bug in jsctags, make sure that you are not concerned by it.

  • jsctags is better than ctags when you write crazy "modern" JavaScript with lots of callbacks and self-executing functions. If your JavaScript is more traditional, ctags may be enough.

like image 139
romainl Avatar answered Nov 01 '22 12:11

romainl