Best Way to Set up Ctags with Neovim and Vim 8

November 05, 2017

Ctags are a great way to navigate large projects when using Vim or Neovim by jumping to definition with a simple command. With the recent addition of async jobs in Vim 8 and Neovim, you can now generate your project’s tags in the background, making the whole process relatively seamless.

Prerequisites

  • Mac OSX (for this tutorial, can be installed on other operating systems)
  • Homebrew

Install universal-ctags

First, we’ll install universal-ctags for our OS. Universal-ctags is an actively maintained ctags implementation (as of November 2017). This tool will allow us to generate the tag file for our project:

Using homebrew:

brew install --HEAD universal-ctags/universal-ctags/universal-ctags

Install vim-gutentags

Next, we’ll install vim-gutentags which is an awesome plugin that makes managing our tag file painless. When opening a project for the first time, vim-gutentags will kick off the creation of our tag file in the background. For subsequent opens, it will asynchronously update our tag file on save.

Using the syntax for your respective package manager (I use vim-plug), add the following to your .vimrc (Vim users) or init.vim (Neovim users):

Plug 'ludovicchabant/vim-gutentags'

And install:

:PlugInstall

Jump Around

Navigate to a project that you’d like to generate tags for and open it with Vim or Neovim. The tag creation will kick off in the background and it may take a few minutes for it to finish depending on the size of the project. Once finished, you can use C-] to jump to definition.

Enjoy project navigation bliss.

Josh Kuiros
I'm the CTO of Outline, based in San Francisco. I'm passionate about building human-centered software and strong engineering teams. Outside of code, you can find me cycling around the Bay Area.