Vim tags

From Schmid.wiki
Jump to: navigation, search

Tags File

Tags enables easy source code navigation in Vim. If a tags file named 'tags' is present in the current directory, it will be auto-loaded by Vim. If exuberant-ctags is installed, the tags file can be generated by this command:

   ctags -R --extra=+fq .
-R         means recurse directories
--extra=+f means include a tag for each file
--extra=+q means include tags with scope, e.g. 'ClassName.MethodName' as well as just 'MethodName'

Mapping this to a hotkey to enable quick update of tags file could be done like this:

   map <Leader>t :!/opt/local/bin/ctags -R --extra=+fq .<cr>

Tag Jumping

Stag (horizontal).

Examples:

:tag filename.something
:tag ClassName.MethodName
:tag MethodName
:tag /^Met.*Name
:stag name         - horizontal split and jump to tag
:vert stag name    - vertical split and jump to tag

Or press Ctrl+] when cursor is on top of a name to jump to the definition of that name.

Tag Previewing

If you just want to remind yourself of method arguments, you could use :ptag instead of :tag.

Also, use Ctrl+W } instead of Ctrl+].

Preview window is closed with Ctrl+W z.

Personal tools