7

I'm writing javascript code using vim and I really like to have outline view for the current javascript file I'm editing. I find tagbar is the popular plugin for this purpose. And on its wiki, for javascript to work, it recommends jsctags depends on Tern.

Now

  1. I have installed vim plugins: tagbar and tern_for_vim.
  2. I've installed exuberant ctags and put its bin into path
  3. I have installed jsctags

I open a js file in vim, and open the tagbar outline view, but there's no tags showing.

So I try running jsctags against a js file in command line directly, still, nothing is outputted.

has anyone successfully make this combination work? Can someone share some thoughts?

5
  • 4
    So what's your question exactly? You followed some instructions somewhere (where? what exactly did you do?) and something doesn't work (what?) as you're expecting (what did you expect?) Mar 15, 2015 at 6:08
  • Part of the process Aaron didn't mention is actually generating the tags file. That might be possible by running something on the shell: jsctags *.js **/*.js Mar 17, 2015 at 0:18
  • Your question is better after your edit ;-) But I think this question would probably get better answers if you would include a (small) vimrc file and (small) JS file that clearly demonstrate the problem. This would reduce the effort required by the potential answerer to get started in investigating your problem ;-) Mar 31, 2015 at 9:33
  • 1
    @joeytwiddle The Tagbar plugin uses the external tools to create its own tags file. You shouldn't need to do it manually on the command line.
    – Rich
    Mar 31, 2015 at 14:21
  • 2
    I've rolled back your Rev 4 → 3. Please post the resolution as a self-answer instead. Apr 8, 2015 at 13:48

2 Answers 2

4
:g/func/#

gives you an actionable outline of the current JavaScript buffer without installing any third party plugin or requiring any external program.

Use func\|var to include variable declarations.

3
  • What do you mean "actionable"? Or more specifically, what actions can I take, and how? Mar 16, 2015 at 23:05
  • I suppose typing :[line_number] is the obvious action. I can also yank the last line with /y or delete all of them with /d. (I just stumbled across the holy grail.) Is there any way to yank all the lines? Mar 17, 2015 at 0:30
  • @joeytwiddle, yes, :23<CR> is the obvious one. You can use :g//y A to yank all the lines in the output to register a.
    – romainl
    Mar 17, 2015 at 6:44
1

I've developed a set of CTAGS regex rules for JavaScript and CoffeeScript. My rules include unit tests so I think they are more reliable than most.

Here's my git repo which should be most up to date: https://github.com/winstonwolff/ctags-javascript-coffeescript

And here are the rules I use as of writing this post:

--languages=-JavaScript
--langdef=js
--langmap=js:.js
--regex-js=/^var[ \t]+([a-zA-Z0-9._$]+) = \[/\1/a,array/
--regex-js=/^var[ \t]+([a-zA-Z0-9._$]+) = \{/\1/o,object/
--regex-js=/^var[ \t]+([a-zA-Z0-9._$]+)[ \t]*=[^{\[]*$/\1/r,var/

--regex-js=/^var[ \t]+([A-Za-z0-9._$]+)[ \t]*=[ \t]*[A-Za-z0-9_$]+.extend/\1/f,function/
--regex-js=/^[ \t]*([A-Za-z0-9_$]*\.)*([A-Za-z0-9_$]+)[ \t]*[:=][ \t]*function/\2/f,function/
--regex-js=/^[ \t]*function[ \t]*([A-Za-z0-9_$]+)[ \t]*\(/\1/f,function/
--regex-js=/^[ \t]*var[ \t]+([A-Za-z0-9_$]*\.)*([A-Za-z0-9_$]+)[ \t]*=[ \t]function/\2/f,function/

--regex-js=/(jQuery|\$)\([ \t]*([^ \t]*)[ \t]*\)\.bind\([ \t]*['"](.*)['"]/\2.\3/f,function/

--regex-js=/^[ \t]*describe[ \t]*\([ \t]*["'](.*)["']/\1/f,function/
--regex-js=/^([ \t]*)(describe|context|it)[ \t]*\([ \t]*["'](.*)["']/.\1\3/f,function/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.