开发者

Using ctags and vim with new file extension mappings

Drupal modules are php files with .module file extensions. To generate tags on these files I run ctags with the following langmap settings:

ctags -R --langmap=php:+.module .

This command produces tags file with several tags belonging to .module file. But when I open the taglist window with TlistToggle none of the tags are shown. However, when opening a php file with .开发者_StackOverflowphp extension, taglist window displays all the tags in a navigation tree.

Do I need to specify somehow to Vim's taglist plugin that .module file extension belongs to php language?

Update: I run the following diagnose command described in taglist's faq:

ctags  -f - --format=2 --excmd=pattern --fields=nks test_module.module

The reply is nothing. But when I run this command with a php file it displays a list of tags:

ctags  -f - --format=2 --excmd=pattern --fields=nks test_module.php


Both Vim and Emacs will read “editor hints” in the file: text, usually embedded in a comment, that contains commands or settings for the editor to obey when opening the file. You can use that to tell the editor what to do with the file, regardless of the filename.

For hints that will work with both Emacs and Vim, place a comment block at the end of the file:

# Local variables:
# coding: utf-8
# mode: php
# End:
# vim: fileencoding=utf-8 filetype=php :

(Your question doesn't entail the need to specify character encoding, but this shows how you can combine multiple settings in one comment block.)


You can see the default language-mappings with ctags --verbose

Drupal extensions probably aren't included by default. You might see something like this for PHP: PHP: .php .php3 .phtml

Sometimes long files can create errors, so I typically exclude extensions that tend to have minified output. Drupal uses ".inc" often as well. This command should work:

ctags -R --langmap=PHP:+.inc.module --exclude='*.js' --exclude='*.html' --exclude='*.css' *

In ~/.vimrc make sure to add: :set tags=/path/to/your/tags

Then you should be able to use Ctrl+] to jump to class/function definitions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜