Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

spooner1887

macrumors newbie
Original poster
Oct 11, 2010
12
0
Hello,

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.

Thanks!
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
You use the autocommand feature of Vim.

Code:
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.
 

plinden

macrumors 601
Apr 8, 2004
4,029
142
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
 

spooner1887

macrumors newbie
Original poster
Oct 11, 2010
12
0
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?


Thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.