Discussion in 'Mac Programming' started by spooner1887, Feb 10, 2012.

  1. spooner1887 macrumors newbie

    Oct 11, 2010

    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.

  2. robvas macrumors 68030

    Mar 29, 2009
  3. jiminaus macrumors 65816


    Dec 16, 2010
    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.
  4. plinden macrumors 68040


    Apr 8, 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
  5. spooner1887 thread starter macrumors newbie

    Oct 11, 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?

  6. robvas macrumors 68030

    Mar 29, 2009
    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.

Share This Page