For example, if I want to have a file with the name gitconfig (no leading .) be recognised by vim as being of filetype=gitconfig, is there a means of indicating this in a comment or something similar within the file itself? Note, I want this to work across systems, so modifying vim's startup files is not preferred.

2 Answers 2


This sounds like the modeline feature (see the on-line help). In gitconfig you could have a modeline like the following, near the beginning or end of the file:

# vi: ft=gitconfig

This requires modelines to be enabled and since they can be a security hazard they are disabled by default on many systems though.

Another approach which might be slightly more work is to make a .vim file containing

au BufRead,BufNewFile */gitconfig setfiletype gitconfig

and drop it in ~/.vim/ftdetect on all your systems.

  • Perfect, modeline is what I was looking for. modeline is enabled, but it looks like something else in my setup is interfering with it. If I put your suggested line at the top of the file, then after I reopen it set filetype? reveals filetype 'conf'. Aug 31, 2011 at 23:21
  • Maybe you can use :verbose set filetype to see where the conf value comes from - I would guess vim's system default filetype settings somewhere.
    – jw013
    Aug 31, 2011 at 23:43
  • apparently it was last set from /usr/share/vim/vim73/filetype.vim. Why would system level filetype detection override the directive I've placed in the file itself? Sep 4, 2011 at 0:15
  • were you running vim as root? if yes, I think the modeline wouldn't load.
    – elias
    Jan 7, 2013 at 20:15
  • Also check the value of the modelines option. :set modelines? If it's set to zero, it won't process the modeline. Jun 17, 2015 at 17:00

You can create a syntax file and put it in vim's share/syntax directory (on Debian Lenny it's /usr/share/vim/vim71/syntax (your distro may vary)).

Documentation on Vim's syntax format is here: http://vimdoc.sourceforge.net/htmldoc/syntax.html

You may be able to find a ready syntax file on the Internet somewhere, but I'll leave that as an exercise for you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .