View Full Version : .vimrc

Feb 10, 2012, 02:23 PM

I was wondering if it is possible to set a particular syntax highlighting for a particular file type (i.e. peachpuff.vim for *.c) and a different syntax highlighting for a different file type (i.e. zellner.vim for *.py).

I would think that this is possible, but can it be easily done in the .vimrc file. I am hoping that I can just use something to the effect

if (*.c) use peachpuff
else use zellner

But I'm not sure how to do if statements and such in my vimrc file.


Feb 10, 2012, 02:43 PM
Sure, you just need to create syntax files (or find existing ones) and tell vim you want to use them:


Feb 10, 2012, 02:48 PM
You use the autocommand feature of Vim.

syntax on " Turn on syntax highlighting
filetype on " Turn on file type auto detection
au FileNewFile, BufRead *.c set filetype=c
au FileNewFile, BufRead *.py set filetype=python

But before you starting adding au command for every filetype, the filetype on command will cause vim to try to recognise the types of many files. You only need to add au lines for extensions that are not automatically detected.

The code for auto-detecting filetypes is in /usr/share/vim/vim73/filetype.vim. Looking at this code will also show you how to code a if...elseif...else...endif construct.

Feb 10, 2012, 02:56 PM
If you want zellner to be the default, in .vimrc put:
colorscheme Zelda

Then make file ~/.vim/after/ftplugin/c.vim

In c.vim put the line (and whatever else specific to c you want):
colorscheme peachpuff

Feb 11, 2012, 11:14 AM
Thank you all for the responses. The link provided by robvas was quite helpful and I've been tinkering with my settings to get my syntax highlighting just right.

Also, I was wondering if you all know if it is possible to get more syntax colors for vim? I can set ctermfg = 1 to 8, but numbers higher than 8 give my just black. FYI, I do not have the GUI version, it appears that the GUI version has more available colors. Will I need more to install the gui version of vim to get more colors?


Feb 11, 2012, 11:49 AM
If you are on Snow Leopard you will have to use another terminal program like iTerm - Terminal doesn't support 256 colors until OS X Lion

You can run this script to see how many colors your terminal supports:


Save it and chmod the file to 755 so you can run it.