Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

When I open vim for a file like /etc/nginx/sites-available/default, syntax highlighting works fine. But then if I create my own file /etc/nginx/sites-available/myapp, vim does not highlight its syntax. I have to do :setf conf every time.

Is there anything I can put in ~/.vimrc to tell vim "if you don't know which syntax to use, just use conf" ?

A .vimrc template for a vim noob is also welcome. I'm not using it as an IDE, I use vim mostly for config files only.

Note: I'm using Ubuntu 12, in case it matters.

share|improve this question
    
I changed your title to more accurately reflect what you are trying to do and re-asked the question here, since this can be useful in the general case: serverfault.com/a/390801/2101 –  MikeyB May 20 '12 at 12:59
    
@MikeyB I didn't know or care about 'filetypes', as far as I knew vim could have been doing the syntax highlighting just by looking at the code and guessing the language. And the main part of the problem was that I wanted it to be 'by default'. I already knew how to 'set the language/filetype when editing'. Also, whether it is for nginx or anything else, is irrelevant. Do as you want, I never understood why serverfault people decide to close or edit questions (for SEO maybe?). Unless grammatically incorrect, the original title reflected my problem. –  HappyDeveloper May 20 '12 at 15:26
2  
possibly interesting: vim.org/scripts/script.php?script_id=1886 (I use it and it's pretty nice, add a # vim:syn=nginx at the bottom of the configs) –  TokenMacGuy May 20 '12 at 17:37
    
@HappyDeveloper: the reason I edited it was that your accepted answer indicates "Oh, I really was trying to do that." Now future visitors will be able to search for 'default vim filetype' or 'default vim syntax' and get the correct answer for that instead of getting frustrated since the accepted answer doesn't say how to accomplish the title of the question. Plus, now you also know how to set the default filetype :) –  MikeyB May 20 '12 at 17:49
    
@MikeyB The new title doesn't even use the word 'default'. The original one did. –  HappyDeveloper May 21 '12 at 10:13

1 Answer 1

up vote 12 down vote accepted

The following line in ~/.vimrc should do this.

autocmd BufRead,BufNewFile /etc/nginx/sites-*/* setfiletype conf
share|improve this answer
    
Thanks! ####### –  HappyDeveloper May 20 '12 at 5:42
    
slight correction autocmd BufRead,BufNewFile /etc/nginx/sites-/ setfiletype conf –  user123094 May 31 '12 at 20:05

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.