.vimrc

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

  1. macrumors newbie

    Joined:
    Oct 11, 2010
    #1
    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!
     
  2. macrumors 68000

    Joined:
    Mar 29, 2009
    Location:
    USA
    #2
  3. macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #3
    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.
     
  4. macrumors 68040

    plinden

    Joined:
    Apr 8, 2004
    #4
    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. thread starter macrumors newbie

    Joined:
    Oct 11, 2010
    #5
    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!
     
  6. macrumors 68000

    Joined:
    Mar 29, 2009
    Location:
    USA
    #6
    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_script.php?src_id=4568

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

Share This Page