15

I'm looking to enable color syntax highlighting in vi. I just enabled colors in Terminal via here. Any ideas on how to enable this?

NOTE: Usually on Linux when I open vi with vi file.txt and it opens in black and white on default, I can open the same file with vim file.txt and it will show the colors, but this does not work here.

1

3 Answers 3

15

It’s a matter of having the right settings in your ~/.vimrc file. Here’s mine: https://github.com/mathiasbynens/dotfiles/blob/master/.vimrc.

The key is to add this:

" Enable syntax highlighting
syntax on

You can install color schemes in your ~/.vim/colors directory. To enable a colorscheme, use:

" Select a colorscheme
colorscheme molokai

I’m using Molokai, which looks like this when editing a JavaScript file:

3
  • Thanks, this is exactly what I was looking for! EDIT: On a side note, adding colorsheme molokai yielded E185: Cannot find color scheme molokai. But the syntax part still worked! :) Mar 29, 2012 at 16:36
  • @gusterlover6 Yeah, as I explained in my post you need to have the Molokai colorscheme installed in ~/.vim/colors/molokai.vim. You can download it from the link in my answer. Enjoy! Mar 29, 2012 at 16:43
  • If you use Janus you get easy access to colour schemes (and plugins).
    – Ian C.
    Mar 29, 2012 at 16:52
5

I'll also say that MacVim is a nice upgrade from the standard Vim that ships with OS X, but it isn't necessary. What you need is Vim configuration that adds syntax highlighting to VIM.

The fastest way to get that is with Janus -- it's a set of VIM plugins and configuration files pre-configured and ready to go. It works with Vim and MacVim.

To install it:

curl -Lo- http://bit.ly/janus-bootstrap | bash

And then follow the instructions. That calls their automatic installer. It requires Vim 7.3 or greater. You'll get an easy path to colours and plugins in Vim.

Vim with Janus

1
  • @denis yes, please ask a new question.
    – Ian C.
    Dec 6, 2016 at 23:50
4

You need to customize your ~/.vimrc to enable syntax highlighting, among other things. Very simplistically, you'll want to add:

syntax on

Google "vimrc" for sample vim configuration files.

1
  • 1
    It drives me mad when people say to "google stuff" in a stackexchange answer - how do you think folks got to the question in the first place?!
    – ZincX
    Jun 11, 2013 at 9:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .