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