Getting started with ctags + Vim on MacOS

Alex Galea
Mar 21, 2018 · 2 min read

A quickstart guide will show you how to setup and run ctags on MacOS with Vim. You’ll see how ctags lets you quickly hop from an instance of a function to its definition, and back again.

Installation

If you’re on Mac then I would suggest downloading an upgraded version with homebrew:

brew install ctags

Afterwards, you may need to set the alias to the new version by running:

alias ctags="`brew --prefix`/bin/ctags"
alias ctags >> ~/.bashrc

The second line saves the newly mapped ctags alias so you don’t need to rerun the first line every session. For me it added ctags=/usr/local/bin/ctags to the .bashrc file.

I then added set tags=tags to my .vimrc file with:

echo "set tags=tags" >> ~/.vimrc

This will tell vim to look for the ctags index file in the source directory.

Using it

Navigate to the source directory and type:

ctags -R .

Now you should see a newly created file named tags containing the index.

While still in the source directory, open vim up by typing:

vim

Then navigate to a file and open it. This file should contain an instance of a function that’s defined somewhere else in the source directory.

Move your cursor to some function instance and type:

Ctrl + ]

This should bring you to the functions definition inside vim. You can go back to the instance by typing:

Ctrl + T

Instead of Ctrl + ], you can use this trick to open the function definition in a slit:

Ctrl + W  Ctrl + ]

Then you can navigate between the panes by doing

Ctrl + W  Ctrl + (arrow key)

Thanks for reading and enjoy using ctags 👏

If you want to chat, you can get in touch with me here on Twitter

Alex Galea

Written by

Senior Data Analyst, MSc. Physics

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade