set filetype
通过调用所有的FileType
自动命令来改变vim处理文件的方式。它不会持续。如果你想始终打开该文件与filetype=apache
,你可以添加以下到您的.vimrc
:
au BufRead,BufNewFile /etc/apache2/sites-available/www.example.com set filetype=apache
您可以阅读更多关于它:
:help 'filetype'
:help filetypes
:help :autocmd
:help .vimrc
编辑:在我/usr/share/vim/vim73/filetype.vim
发现:
au BufNewFile,BufRead access.conf*,apache.conf*,apache2.conf*,httpd.conf*,srm.conf* call s:StarSetf('apache')
au BufNewFile,BufRead */etc/apache2/*.conf*,*/etc/apache2/conf.*/*,*/etc/apache2/mods-*/*,*/etc/apache2/sites-*/*,*/etc/httpd/conf.d/*.conf* call s:StarSetf('apache')
s:StarSetf
将setfiletype
至apache
如果文件类型与忽略模式不匹配。在我的系统上,:echo g:ft_ignore_pat
将只显示被忽略的归档文件扩展名。 setfiletype
确实set filetype
,但只有一次。
因此,至少在我的系统中,*/etc/apache2/sites-*/*
模式会捕获您的文件名并将其作为apache
文件。
这看起来像是一个非常糟糕的解决方案,因为它可能会不合理地变大。 – puk 2012-01-10 13:57:01
vim知道如何通过使用扩展模式自动打开一些文件。特别是,'/ etc/apache2'中的'* .conf'文件被自动分配'filetype = apache'。你也可以为'/ etc/apache2/sites-available/*'制作一个包含模式。否则......好吧,强硬。 – Amadan 2012-01-10 14:01:59
现在我检查了'/ etc/apache2/sites-available/*'应该已经默认为'filetype = apache' ... – Amadan 2012-01-10 14:04:04