Enable syntax highlighting in Vi?

Discussion in 'Mac Programming' started by Cromulent, Jul 8, 2009.

  1. Cromulent macrumors 603


    Oct 2, 2006
    The Land of Hope and Glory
    I've been broken down, after hearing what must be hundreds of people constantly recommend learning Vi I decided to give it a shot. But I can't work out how to enable syntax highlighting, I have the relevant syntax file for C and have put it in ~/.vim/syntax/c.vim but nothing works.

    Any advice? Also if anyone has any cool tips for setting Vi up on Mac OS X to work well as a programming tool (configuration options etc) they would be appreciated :).
  2. ChOas macrumors regular

    Nov 24, 2006
    The Netherlands
    For me it's just syn on in vim.

    (so ESC,colon,'syn on' :) )

    another option is putting syntax on in ~/.vimrc

    my ~/.vimrc:

    xxx $ cat ~/.vimrc
    syntax on
    colorscheme evening
    xxx $
  3. John Jacob macrumors 6502a

    John Jacob

    Feb 11, 2003
    Columbia, MD
    Why don't you try using MacVim? Vi with an OS X native GUI, and it enables syntax highlighting by default.

    Although, I prefer Nedit. :D
  4. Cromulent thread starter macrumors 603


    Oct 2, 2006
    The Land of Hope and Glory
    Because I need to work with an OpenBSD system as well. So I need to learn how to use the basic version of Vi included with all Unix like operating systems.

    Edit: Huzzah, got it working. I had to download the source distribution and copy all the relevant files into the syntax directory. Now I have highlighting for any number of languages that I will never know :).
  5. mslide macrumors 6502a

    Sep 17, 2007
    If you really want to use the traditional vi, instead of something like vim, then you won't have multiple undoes or syntax highlighting. I could be wrong, but I'm pretty sure the traditional vi doesn't support that stuff. In fact, I think the traditional vi doesn't support split windows either.

    The point is that most unix systems, including osx, actually ship with vim and not the traditional vi. So you might not want to bother worrying about things that are only supported in one vs the other. Many websites that teach you how to use "vi" actually mean "vim".

    I second John Jacob's MacVim comment, if you also want the option of vim with a gui. It's nice to have so you can setup file associations so that it will fire up macvim, instead of xcode, when you double-click on a file... if you prefer that anyway.

Share This Page