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,824
2 Answers
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.
- 51,212
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.
- 39,666
- 4
- 75
- 104
set filetype?reveals filetype 'conf'. – Murali Suriar Aug 31 '11 at 23:21:verbose set filetypeto see where theconfvalue comes from - I would guess vim's system default filetype settings somewhere. – jw013 Aug 31 '11 at 23:43modelinesoption.:set modelines?If it's set to zero, it won't process the modeline. – Christian Long Jun 17 '15 at 17:00