PDA

View Full Version : Enable syntax highlighting in Vi?




Cromulent
Jul 8, 2009, 02:27 AM
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 :).



ChOas
Jul 8, 2009, 02:36 AM
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 :).

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 $

John Jacob
Jul 8, 2009, 03:29 AM
Why don't you try using MacVim (http://macvim.org/OSX/index.php)? Vi with an OS X native GUI, and it enables syntax highlighting by default.

Although, I prefer Nedit. :D

Cromulent
Jul 8, 2009, 03:44 AM
Why don't you try using MacVim (http://macvim.org/OSX/index.php)? Vi with an OS X native GUI, and it enables syntax highlighting by default.

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

mslide
Jul 8, 2009, 09:56 AM
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.

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.