Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 10, 2012, 03:23 PM   #1
spooner1887
macrumors newbie
 
Join Date: Oct 2010
.vimrc

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!
spooner1887 is offline   0 Reply With Quote
Old Feb 10, 2012, 03:43 PM   #2
robvas
macrumors 68000
 
Join Date: Mar 2009
Location: USA
Sure, you just need to create syntax files (or find existing ones) and tell vim you want to use them:

http://vimdoc.sourceforge.net/htmldo...tml#:syn-files
robvas is offline   0 Reply With Quote
Old Feb 10, 2012, 03:48 PM   #3
jiminaus
macrumors 65816
 
Join Date: Dec 2010
Location: 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.
jiminaus is offline   0 Reply With Quote
Old Feb 10, 2012, 03:56 PM   #4
plinden
macrumors 68040
 
plinden's Avatar
 
Join Date: Apr 2004
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
plinden is offline   0 Reply With Quote
Old Feb 11, 2012, 12:14 PM   #5
spooner1887
Thread Starter
macrumors newbie
 
Join Date: Oct 2010
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!
spooner1887 is offline   0 Reply With Quote
Old Feb 11, 2012, 12:49 PM   #6
robvas
macrumors 68000
 
Join Date: Mar 2009
Location: USA
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:

http://www.vim.org/scripts/download_...hp?src_id=4568

Save it and chmod the file to 755 so you can run it.
robvas is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump

All times are GMT -5. The time now is 07:21 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC