Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers 2

up vote 13 down vote accepted

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.

share|improve this answer
    
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'. –  Murali Suriar Aug 31 '11 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 '11 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? –  Murali Suriar Sep 4 '11 at 0:15
    
were you running vim as root? if yes, I think the modeline wouldn't load. –  elias Jan 7 '13 at 20:15
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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.