This Sublime Text 2 Package provides support for working with tags generated by Exuberant CTags
The ctags command is searched for on the system PATH. It works by doing a binary search of a memory-mapped tags file, so it will work efficiently with very large (50MB+) tags files if needed.
The easiest way to install this plugin, is to use the Package Control plugin (written by Will Bond)
Go to your Sublime Text 2 Packages directory and clone the repository using the command below:
$ git clone https://github.com/SublimeText/CTags CTags
- Download the files using the .zip download option
- Unzip the files (and rename the folder to CTags if needed)
- Copy the folder to your Sublime Text 2 Packages directory
If anyone is having trouble getting the CTags -R flag to work on OSX, you are probably using the stock CTags installation.
To get a proper copy of ctags, use one of the following options:
- Make sure that Sublime Text is using the right version of CTags:*
- If 'which ctags' doesn't point at ctags in '/usr/local/bin', make sure you add '/usr/local/bin' to your PATH ahead of the folder 'which ctags' reported.
- Add or modify the 'export PATH=...' (e.g. in /.profile) to make the change permanent
To get a proper copy of ctags:
- In a terminal session: sudo apt-get install ctags
Download the binary ctags.exe from Exuberant CTags site.
Extract ctags.exe from the download zip to "C:\Program Files\Sublime Text 2" or any folder that within your PATH so that Sublime Text 2 can run it.
See this forum thread for a bit of background.
This uses .tags files created in ctags -R -f .tags recursive mode (by default).
The plugin will try to find a .tags file in the same directory as the current view, walking up directories until it finds one. If it can't find one it will offer to build one ( in the directory of the current view )
If a symbol can't be found in a tags file, it will search in additional locations that are specified in the CTags.sublime-settings file (see below).
If you are a Rubyist, you can build a Ruby Gem's tags with the following script:
require 'bundler' paths = Bundler.load.specs.map(&:full_gem_path) system("ctags -R -f .gemtags #{paths.join(' ')}")
By default, Sublime will include ctags files in your project, which causes them to show up in the file tree and search results. To disable this behaviour you should add a file_exclude_patterns entry to your Preferences.sublime-settings or your project file.
e.g.:
"file_exclude_patterns": [".tags", ".tags_sorted_by_file", ".gemtags"]
There's a CTags.sublime-settings file:
{ "debug" : false, "ctags_command" : "ctags -R -f .tags", "filters" : { "source.python": {"type":"^i$"} }, "definition_filters": { "source.php": {"type":"^v$"} }, "definition_current_first": false, "show_context_menus": false, "extra_tag_paths" : [ [["source.python", "windows"], "C:\\Python27\\Lib\\tags"]], "extra_tag_files" : [".gemtags"] }
filters will allow you to set scope specific filters against a field of the tag. In the excerpt above, imports tags like "from a import b" are filtered.
'(?P<symbol>[^\t]+)\t' '(?P<filename>[^\t]+)\t' '(?P<ex_command>.*?);"\t' '(?P<type>[^\t\r\n]+)' '(?:\t(?P<fields>.*))?'
extra_tag_paths is a list of extra places to look for keyed by (selector, platform)
extra_tag_files is a list of extra files relative to the original .tags file
Note the platform (windows in the example above) is tested against sublime.platform() so any values that function returns are valid.
The rest of the options are fairly self explanatory.
If there are any problems or you have a suggestion, open an issue, and we will receive a notification.
Thanks :)
Command | Key Binding | Alt Binding | Mouse Binding |
---|---|---|---|
rebuild_ctags | ctrl+t ctrl+r | ||
navigate_to_definition | ctrl+t ctrl+t | ctrl+> | ctrl+shift+left_click |
jump_back | ctrl+t ctrl+b | ctrl+< | ctrl+shift+right_click |
jump_back to_last_modification | ctrl+t ctrl+m | ||
show_symbols | alt+s | ||
show_symbols multi | alt+shift+s | ||
show_symbols suffix | ctrl+alt+shift+s |