How to Enable VIM Syntax Highlighting on MAC OSX

For some people VIM is the primary code editor and some people use it to make minor edits to their code. Whatever your use case might be, it’s always good to have some syntax highlighting. It makes the code more readable and reduces errors.

Syntax highlighting / Color coding is not turned on MAC by default. Turning it on is a very simple task.

Open your terminal, it will be in Applications/utilities folder.

Type in the following command to open up the VI editor preferences file

vi ~/.vimrc

Most probably it will be empty. Whether its empty or not, add this code at the very end.

filetype plugin indent on
syntax on 

Code to add Syntax Highlighting on MAC

Bonus tip: If you are wondering how we got the line numbers in the above screenshot

  1. Press the Esc key if you are currently in insert or append mode.
  2. Press : (the colon). The cursor should reappear at the lower left corner of the screen next to a : prompt.
  3. Enter the following command: set number.
  4. A column of sequential line numbers will then appear at the left side of the screen.

You can even add set number at the end of above two lines in ~/.vimrc to make it always show the line numbers.

vi without color coding
vi without color coding
VI with color coding and line numbers enabled
VI with color coding and line numbers enabled

Leave a Reply

Your email address will not be published. Required fields are marked *