Skip to content

Instantly share code, notes, and snippets.

@yujinyuz
Forked from przbadu/Ctags.md
Created February 16, 2020 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yujinyuz/2416a0b695e229e02bf1f4a0f7da3463 to your computer and use it in GitHub Desktop.
Save yujinyuz/2416a0b695e229e02bf1f4a0f7da3463 to your computer and use it in GitHub Desktop.
Ctags for ruby on rails and node applications

Install ctags

http://ctags.sourceforge.net follow this url for installation and documentation.

Ctags with Ruby/Rails

We can ctags lots of programming languages. Here is how to do it for ruby/rails. I really like how RubyMine jumps to the source code (either withing project score or to the gem source). This is really useful for reading source code for those classes, methods, modules etc. But Now that I use vim as My IDE/Editor I really like that functionality to happen in my vim editor. And I found ctags as the solution.

NOTE: you can use ctags or etags for emacs too ;)

Generate ctags for our project

goto root of your project and generate ctags. `$(bundle list --paths) will tags our gems :) .

ctags -R --languages=ruby --exclude=.git --exclude=log --exclude=tmp . $(bundle list --paths)

It will generate ctags in our root directory, we can add it to .gitignore if we want.

Now open your project in vim and then you can jump to source definition by doing :tags has_many and ctags will open /path/to/associations.rb file and put our cursor in has_many(...) function definition. Wow!!

But wait, we can also quickly jump to those method definitions from our model/controller etc directly by moving our cursor to the (anywhere in has_many in our model) and then press C-]. Isn't that cool ;)

Generate ctags for node js application

Lets say we wanna generate ctags for node applications e.g: ember app, react app, angular app or any node apps. We can do that by NOT IGNORING node_modules directory.

ctags -R --exclude.git --exclude=tmp .

It will generate ctags for our current node application including node_modules/ or bower_components/ directory. Now we can jump to any method definitions using C-]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment