Exuberant ctags allow you to jump to definition of the method / object you have under your cursor. Here is how to set them up:
sudo apt install exuberant-ctags
Create .ctags
file in your home directory
This file is for storing configuration, mine looks like this:
--exclude=.git
--exclude=node_modules
--exclude=log
--exclude=vendor
--exclude=tmp
--exclude=legacy <-- very nice for working with pytorch
Navigate to a directory with code you are working on.
This directory will be searched automatically. Create a file listing other directories you would like to index.
In root of the fastai library I have a .srclist file containing the following line:
/home/radek/workspace/pytorch
ctags -R -L .srclist .
-R
tells ctags to recursively look at directories within the current directory-L
tells ctags to look at the listed locationsYou are now ready to start using ctags in vim
ctrl+]
takes you to the tag under cursorctrl+t
takes you back
For tags resolving to multiple source locations
:tnext
or :tn
takes you to the next location:tprev
or :tp
takes you to the previous loation:ts
lists all source locations15 * * * * ctags -R -L .srclist ~/workspace/fastai/fastai
:tag
is handy and supports tab completionmapping ctrl-]
to :ts
is a good idea
This is what you need to add to .vimrc
for this:
noremap <C-]> g<C-]>
(gives you a list for multiple defs and jumps immediately for single def)