Vim: GoTo Tag Definition
Category: Developer Tools
January 2021

There are multiple ways of doing anything with vim, including going to where a function or object is defined, and I usually need to do something at least 3 times before I can do it without breaking my focus or train of thought.

My memory is hazy but I remember spending a 1/2 day looking into this and considering which solution I wanted to commit to.1 My options seemed to be between YouCompleteMe and ALE. [Update!2]

I can’t remember everything I read and tried, but I trust my conclusions. Looking in my .vimrc I see that I have <leader>x mapped to :YcmCompleter GoTo and it works just fine, even when a module is imported from somewhere outside the current project. The tool was working and ready to use, I just hadn’t internalized it yet.

Commands to remember:

  • <Leader>x - GoTo definition - YCMs best guess at an ‘intelligent’ goto command, whether its a declaration or a definition.
  • <F2> - Toggle tagbar

Jump Lists and Change Lists

If you’re going to be jumping around to where things are defined, you will need to know how to jump back again. It seems there are two lists you need to be aware of, the jump list3 and the change list4.

Jump List

  • A list of locations that the cursor has jumped to.
  • Relevant to jumping to a definition.
  • <C-O> move up the jump list
  • <C-I> mode down the jump list

Change List

  • A list of locations where a change was made.
  • A change is something that can be undone using u.

  • '. will move you to the . mark.

  • . is a special mark that is automatically set at the location of your last edit.
  • '' will bring you back to where you were before your last jump
  • g; and g, will also move you up and down the change list
  1. The more powerful the tool, the more worthwhile it is to take a closer look at what it can and can’t do.
  2. YCM and ALE work fine for goto definition and linting, but they don’t give me satisfactory autocompletion. neoclide/coc.nvim looks like it might offer some improvements. neoclide/coc.nvim
  3. :help jumplist
  4. :help changelist