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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With