最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using tags in Vim - Stack Overflow

programmeradmin1浏览0评论

I know that Vim has sophisticated support for tags but I am struggling to get them to work with JavaScript and TCL.

I am using Vim 7.2.330 under Ubuntu Lucid, a standard Vim install and standard Exuberant CTags install.

I wish to keep my tags in a file called ~/.vimtags/tags

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

I have run the following mand 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 online that said you should add these to make it patible 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 up Vim, the tags file definitely gets loaded. A set tags? shows that the tag file has been included.

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

Please could you share how you set up Vim tags with JavaScript, and also show how you use the tag system? It seems to be a great feature of Vim, if only I could get it working.

I know that Vim has sophisticated support for tags but I am struggling to get them to work with JavaScript and TCL.

I am using Vim 7.2.330 under Ubuntu Lucid, a standard Vim install and standard Exuberant CTags install.

I wish to keep my tags in a file called ~/.vimtags/tags

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

I have run the following mand 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 online that said you should add these to make it patible 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 up Vim, the tags file definitely gets loaded. A set tags? shows that the tag file has been included.

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

Please could you share how you set up Vim tags with JavaScript, and also show how you use the tag system? It seems to be a great feature of Vim, if only I could get it working.

Share Improve this question edited Apr 13, 2011 at 6:07 the Tin Man 161k44 gold badges221 silver badges306 bronze badges asked Jan 20, 2011 at 11:28 mrwoostermrwooster 24.2k12 gold badges40 silver badges48 bronze badges 1
  • How did you resolve this? It looks like at least a couple of people are looking for an answer (2 favourites) but the accepted answer doesn't appear to be the solution to your problem. – intuited Commented Apr 13, 2011 at 7:16
Add a ment  | 

2 Answers 2

Reset to default 3

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

tags are not supposed to work on keywords, they work on symbols you have defined (functions, variables, constants, etc) in the indexed files. So if you are trying on a Javascript keyword it won't work. It won't work on a function from a library either, if you have not included the JS library to your tag file (using ctags -a for example).

If you want to be sure what has been indexed and what you have access to with <C-]>, you can simply open your "tag" file, and see what's in there.

:e ~/.vimtags/tags

You should see a header with information relative to the tag file format, followed by a tag list, which include the tag name followed by a file path, a line number, and a character identifying the type of tag.

If it has some content, it should work for the listed symbols.

Regarding your ctag setup, it looks fine in my opinion.

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

See my answer for this question for more info.

Enjoy. :)

发布评论

评论列表(0)

  1. 暂无评论