Enabling syntax highlighting in vim

July 8, 2012 — 3 Comments

I don’t use vim very often, but when I do it would be handy to have some syntax highlighting. Over on Google+, Vincent Knight shared a link to a post on Geekology that describes how to turn on syntax highlighting and autoindenting for vim on a Mac. Here is a summary.

Open the Terminal and type the following commands.

cd /usr/share/vim
sudo vim vimrc

Press the i key and then paste the following lines of code just below the set backspace=2 line:

set ai                  " auto indenting
set history=100         " keep 100 lines of history
set ruler               " show the cursor position
syntax on               " syntax highlighting
set hlsearch            " highlight the last searched term
filetype plugin on      " use the file type plugins

" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\ if ! exists("g:leave_my_cursor_position_alone") |
\ if line("'"") > 0 && line ("'"") <= line("$") |
\ exe "normal g'"" |
\ endif |
\ endif

Lastly, type Esc followed by :x. That’s it!

Dana Ernst

Posts Twitter Google+

Father of two boys, husband, mathematician, cyclist, trail runner, rock climber, and coffee drinker. Columnist for MAA blog Math Ed Matters.

3 responses to Enabling syntax highlighting in vim

  1. Glad to see you are coming around to the last editor you will ever need!

  2. You should probably put that stuff in a .vimrc file in your home folder. Doesn’t matter when you’ve got the only account on your machine, but it’s a good habit to get into.

  3. Good tip Christian. Thanks.

Leave a Reply