Using tags in Vim

I know that Vim has complex tag support, but I'm struggling to get them to work with JavaScript and TCL.

I use Vim 7.2.330 under Ubuntu Lucid, a standard Vim installation, and standard Exuberant CTags.

I want to save my tags in a file named ~/.vimtags/tags

I have included the tag file in my vimrc file set tags+=$HOME."/vimtags/tags" .

I ran the following command from the base code directory:

 ctags-exuberant -f ~/.vimtags/tags -h ".js" --totals=yes --tag-relative=yes --fields=+akst -R 

I also have the following in my .ctags file - I saw an article somewhere on the web that said you should add them to make it compatible with modern JavaScript.

 --langdef=js --langmap=js:.js --regex-js=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*\{/\1/,object/ --regex-js=/([A-Za-z0-9._$()]+)[ \t]*[:=][ \t]*function[ \t]*\(/\1/,function/ --regex-js=/function[ \t]+([A-Za-z0-9._$]+)[ \t]*\(([^)])\)/\1/,function/ --regex-js=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*\[/\1/,array/ --regex-js=/([^= ]+)[ \t]*=[ \t]*[^"]'[^']*/\1/,string/ --regex-js=/([^= ]+)[ \t]*=[ \t]*[^']"[^"]*/\1/,string/ 

When I load Vim, the tag file definitely loads. A set tags? indicates that the tag file has been included.

However, when I CTRL-] over a keyword, it always says that there are no tags.

Could you share how to configure Vim tags using JavaScript, and also show how you use the tag system? This seems to be a great Vim feature if I could make it work.

+7
source share
2 answers

However, whenever I CTRL-] over a keyword, it always says that there are no tags.

Tags

should not work with keywords , they work with the symbols you defined (functions, variables, constants, etc.) in indexed files. Therefore, if you try to use the Javascript keyword, this will not work. It will not work with a function from the library unless you include the JS library in your tag file (e.g. ctags -a).

If you want to be sure that it has been indexed and with which you have access using <C-]> , you can simply open your "tag" and see what is there.

:e ~/.vimtags/tags

You should see a heading with information regarding the tag file format, followed by a tag list that includes the tag name, followed by the file path, line number, and a character identifying the type of tag.

If it has content, it should work for the characters listed.

As for your ctag setup, this looks good in my opinion.

+3
source

There is a very neat and easy way to get a look at the JavaScript / tag-listing source code in Vim using Mozilla DoctorJS (formerly known as jsctags).

See my answer to this question for more information .

Enjoy. :)

+2
source

All Articles