Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The Apache config file for my website is named Apparently the extension .com is causing vim to set the wrong file type as dcl which makes the syntax highlighting wrong as well. All of my other host config files are correctly identified as Apache files.

I am able to :set filetype=apache and everything looks great but when after closing vim and coming back to edit the file type is back to dcl again.

Other than renaming my host config file, is there a solution to this? Is there a way to make vim remember the filetype of this one particular file? Or better yet, is there a way to correct this wrong file type detection?

EDIT 8/27/13 5:18pm (since superuser is not allowing me to post.. which I might add, is stupid)

As an addition to both the below answers I'd like to share what I did in the end which is to modify the main config file /usr/share/vim/vim73/filetype.vim from:

au BufNewFile,BufRead *.com call s:BindzoneCheck('dcl')


au BufNewFile,BufRead *.com call s:BindzoneCheck('apache')

I realize this may not be appropriate for every user, particularly if you ever intend to write dcl scripts, but in my case this is fine.

share|improve this question
Never do anything in /usr/share/vim/: all your custom stuff must sit in your ~/.vimrc file and your ~/.vim/ directory. – romainl Aug 28 '13 at 7:47
"Never" and "Must" are some pretty strong words there buddy. I believe I can do whatever I'd like, and I just did. However, if you disagree with my method I'm ok with that but perhaps you'd like to explain why in a polite and productive way? – billynoah Aug 28 '13 at 11:10
1. Everything under /usr/share/vim/ is susceptible to be replaced during the next upgrade; do you want your changes to disappear with no way to get them back? 2. The purpose of that dir is to provide a baseline environment; tinkering with it affects Vim's stability and behavior in unpredictable ways. Your change is probably innocuous but any future change may not be. 3. You have a special place under your control where you can do whatever you want to alter Vim's behavior safely and without needing admin rights, use it. 4. ~ is where you traditionally do all your configuration; use it. – romainl Aug 28 '13 at 12:06
thank you. that's some sound reasoning and i'll take your advice on this. – billynoah Aug 28 '13 at 16:43
up vote 7 down vote accepted

One way is to add a modeline to the beginning or end of the file. A basic Vim modeline looks like this:

# vim: ft=apache

The comment character itself is ignored by Vim. There is also an alternative syntax that allows following comment characters as well:

/* vim: set ft=apache: */

Emacs and some other editors use -*- mode: apache -*- instead.

If you wanted to override the file type detection by extension, you could add the following to your ~/.vim/filetype.vim:

augroup filetypedetect
  au BufNewFile,BufRead *.com setl ft=apache
augroup END

(I am not sure if setf apache or setl ft=apache is better.)

Note that the detection isn't entirely wrong, it's merely inaccurate. The OpenVMS operating system uses .com as the extension for "command" files – much like shell scripts or batch files – and they're written in the OpenVMS shell language, DCL (DIGITAL Command Language).

share|improve this answer
Thanks very much! I didn't know about modelines. And yes, I vaguely remember that .com extension from scripting DCL on VMS in the 80's. – billynoah Aug 27 '13 at 21:03

How to do this is described in Vim's built-in reference manual under

:help new-filetype

As explained in section C.2., create a file named ~/.vim/filetype.vim with these contents:

if exists("did_load_filetypes")
augroup filetypedetect
    au! BufRead,BufNewFile *.com setfiletype apache
augroup END

That will recognize any file ending in .com as filetype apache. If you want only to be recognized, change that au line to

au! BufRead,BufNewFile setfiletype apache
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.