Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

How do I tell vim to automatically use a particular filetype (usually for syntax highlighting) when none is detected?

share|improve this question
up vote 4 down vote accepted

Add the following to the end of your ~/.vimrc (change conf to whichever filetype you would like as default):

if &filetype==""
  setfiletype conf
share|improve this answer

From within vim:

 :runtime! syntax/c.vim
share|improve this answer
To be clear, this answer is for setting a filetype automatically when none is detected. This just sets the syntax to a C file at runtime. – MikeyB May 20 '12 at 17:44
@MikeyB See… - it says e.g. au BufNewFile,BufRead * if &syntax == '' | set syntax=html | endif. – ott-- May 21 '12 at 11:50

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.