简体   繁体   English

在新的文件扩展名映射中使用ctags和vim

[英]Using ctags and vim with new file extension mappings

Drupal modules are php files with .module file extensions. Drupal模块是带有.module文件扩展名的php文件。 To generate tags on these files I run ctags with the following langmap settings: 为了在这些文件上生成标签,我使用以下langmap设置运行ctags:

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

This command produces tags file with several tags belonging to .module file. 此命令生成tags文件,属于几个标签.module文件。 But when I open the taglist window with TlistToggle none of the tags are shown. 但是,当我使用TlistToggle打开标签列表窗口时,未显示任何标签。 However, when opening a php file with .php extension, taglist window displays all the tags in a navigation tree. 但是,当打开扩展名为.php的php文件时,标签列表窗口会在导航树中显示所有标签。

Do I need to specify somehow to Vim's taglist plugin that .module file extension belongs to php language? 我是否需要以某种方式为Vim的标签列表插件指定.module文件扩展名属于php语言?

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: 但是,当我使用php文件运行此命令时,它将显示标签列表:

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. Vim和Emacs都将读取文件中的“编辑提示”:通常嵌入在注释中的文本,其中包含命令或设置,供编辑者在打开文件时遵循。 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: 有关同时适用于Emacs和Vim的提示,请在文件末尾放置一个注释块:

# 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 您可以使用ctags --verbose查看默认的语言映射

Drupal extensions probably aren't included by default. 默认情况下,可能不包含Drupal扩展。 You might see something like this for PHP: PHP: .php .php3 .phtml 对于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. Drupal也经常使用“ .inc”。 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 在〜/ .vimrc中,请确保添加:: :set tags=/path/to/your/tags

Then you should be able to use Ctrl + ] to jump to class/function definitions. 然后,您应该可以使用Ctrl + ]跳转到类/函数定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM