Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make vim ctags works for modern javascript

I am using vim and ctags to get taglist. but for javascript, it does not works for this convention

MyClass.extend({   xxx: function(){   },    ... })  MyClass.prototype = {     method : function(){ }  }  MyClass.prototype.method  = function () { } 
like image 443
guilin 桂林 Avatar asked Dec 18 '10 08:12

guilin 桂林


People also ask

Is vim good for JavaScript?

Vim is doing pretty well with syntax JavaScript highlighting out of the box. But it's not ideal. Many of the old syntax plugins for JavaScript have troubles with some modern features like arrow functions or async/await. Here are some plugins that will help to fix it.

How do Ctags work?

Ctags is a tool that will sift through your code, indexing methods, classes, variables, and other identifiers, storing the index in a tags file. The tags file contains a single tag per line. Depending on command line arguments and the language ctags is run against, a lot of information can be obtained from this index.

What are Ctags and Cscope?

cscope, ctags, and Vim are powerful tools for reading a lot of code. ctags can be used to take you to the definition of a variable (e.g., a function, variable, or macro). cscope can be used to take you to the call site of a definition (e.g., all function calls, all variable uses, all macro uses).


2 Answers

Like the others had said: DoctorJS (formerly jsctags) is the best option.

However, integrating it with Vim by writing custom wrappers or using Vim-taglist-plus plugin, which isn't currently working, aren't good solutions.

The easiest way I've found is to install the TagBar Vim plugin (NOTE: It's TagBar, not the old infamous TagList!).

See my other answer for more info.

Edit:

There's a new project called tern.js which should replace the dead doctor.js. See the link above for more info.

like image 191
Ory Band Avatar answered Oct 09 '22 23:10

Ory Band


As @Benoit answered, you can always setup a new languages for ctags; however in the case of JavaScript, you may want to try DoctorJS (formerly jsctags). From the author it is a limited JS environment that records all the functions and objects your script made and turns them into vim-compatible tags file. Here is the original post http://pcwalton.blogspot.com/2010/05/introducing-jsctags.html and its website: http://doctorjs.org/.

To use it with ctags I have to rename the ctags file to smt like ex-ctags and write a wrapper script named ctags which will switch the tool depending on --language.

like image 28
tungd Avatar answered Oct 09 '22 22:10

tungd