Search code examples
javascriptvimctags

Vim ctags jump to class in React


I've used Intellij for many years but I've seen people have success with vim, so I'm trying to learn to use it. I've installed vim and ctags via brew install. I'm used to features like "jump to a file name" and "jump to class name." I ran ctags in my root directory with:

ctags -R .

Now this project I'm exploring was created in Intellij, so I'm trying to jump to the class CreateMerchant.js in src/main/js/create-merchant.js from the root of the project. I tried:

:tag CreateMerchant

But vim tells me Tag not found. I know that class is in the file.

What am I doing wrong? Why can't I jump to the class definition?


Solution

  • I think your class is called CreateMerchant, not CreateMerchant.js.

    Anyway, here are things to try, in order…

    1. Check if ctags actually generated a tags file at the root of the project.

    2. Check if the tags file is not empty. If it is (except for the default headers), then it means that ctags either didn't find any file to index or that it did but it couldn't find anything to tag, there.

    3. Check if you find your CreateMerchant in the tags file. If not, then it probably means that ctags didn't recognize the syntax, which is to be expected if you are using Exuberant ctags. If that's the case, you should probably try Universal ctags or this extensive Exuberant ctags config that I have been maintaining for several years. Both recognize the class syntax as well as many other things missed by vanilla Exuberant ctags.

    As for "jump to a file name", Vim has :help gf for that.