ctags

Jump to: navigation, search
Notice: Moodle Docs will be switched to read-only mode starting on Tuesday 17 October 14:00 UTC for server maintenance. The estimated read-only period should not take more than 24 hours.
Example of auto-completion menu provided by the PHP omnicomplete extension in ViM

Ctags is a tool that generates a tag file of names found in source files. In Moodle, it can be used to index PHP functions, variables, classes and so on. These tags allow definitions to be quickly and easily located by a text editor such as vim.

In the past, the Moodle source code contained a generated tags file to be used directly. If you use this utility these days, you have to generate (and keep up-to-date) the tags file yourself. Please note that most modern IDEs do not need this to provide the functionality.

Obtaining ctags

There are several implementations of the original ctags available these days. Most Moodle developers who use ctags, found https://ctags.io/ a good one.

Generating a tags file

Example of how the tags file can be generated, tuned for Moodle development:

   # cd /path/to/moodle/dirroot/
   # ctags -R --languages=php --fields=+aimS --php-kinds=cdfint --tag-relative=yes --totals=yes --exclude=tags --exclude="config*.php" \
       --exclude="lang/*" --exclude="install/lang/*" --exclude="vendor" --exclude="node_modules" --exclude="moodledata/*" \
       --exclude="phpunit.xml" --exclude=".git/*" --extra=+q

but there are alternative ways too - such as this one.

Using in ViM

The vim editor provides the support for tags file. If you have the tags file generated in the root of the Moodle code, you will probably want something like this in your vimrc file.

set tags=tags,../tags,../../tags,../../../tags,../../../../tags,../../../../../tags,../../../../../../tags,../../../../../../../tags

Once loaded, you can use the tags file to quickly jump and navigate over the Moodle code base:

  • Place the cursor over the tag (e.g., function name) and press CTRL+].
  • Type the command :tag <tagname>
  • To return to your previous location, press CTRL+t

Please refer to your editor help for details and other options.

Integration with PHP omnicomplete

Ctags also play well the the ViM omnicomplete.

See also