Exuberant Ctags

Exuberant Ctags is an external utility that generates tag files. Ctags is available at the following link: http://ctags.sourceforge.net.

If you're on a Debian-flavored distribution, you can install Exuberant Ctags by running sudo apt-get install ctags.

Ctags introduces a ctags binary, which allows you to generate a tags file for your code base. Let's navigate to our project and try it out:

$ ctags -R .

This creates a tags file in the directory you're in.

You may want to set the following option in your .vimrc file:

set tags=tags;  " Look for a tags file recursively in
                                     " parent directories.

This will make sure that Vim looks for the  tags file recursively in parent directories to allow you to use a single tags file for the whole project. Semicolon (;) is what tells Vim to keep looking in parent directories until a tags file is found.

Now, open animal_farm.py in Vim. Place your cursor over a semantically meaningful keyword, for example, the add_animal method on line 26:

Hit Ctrl ] to follow the tag to the definition (which is in a different file—farm.py):

Use Ctrl + t to go back in the tag stack (this will place your cursor back to where it was in the previous file).

Jump list navigation with Ctrl + o and Ctrl + i also works, however, the two are using different lists.

If you have multiple tags with the same name, you can cycle through the available options by using the :tn (next tag) and :tp (previous tag) commands.

You can also bring up a list of tags by using the :ts (tag select) menu. For example, if you jump to the definition of get_kind (using Ctrl + ] from animal.get_kind() in farm.py, for instance) and execute :ts, you'll see the following menu:

You can see what file, class, and method the tag refers to, and you can jump to the desired tag by entering a number.

You can also open a tag and select the menu instead of jumping to the tag under the cursor using g].

You can jump to a tag location immediately as you open Vim. From your prompt, execute the following:

$ vim -t get_kind

This will take you directly to the get_kind tag.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.119.199