Enable syntax highlighting and other options in vim on Mac OS X 10.5.* “Leopard”
Author: willem In: apple, coding, tools, unixVim is a popular UNIX command line text editor with an interface that is based not on menus or icons but on commands given in a text user interface.
Unfortunately the vim that ships with Mac OS X 10.5.* (Leopard) doesn’t have an optimized configuration file to allow for syntax highlighting, auto indentation, etc.
To fix this, open a new Terminal window and enter these commands to open vim’s configuration file:
cd /usr/share/vim sudo vim vimrc
Press the ‘i‘ key to switch vim to Insertion Mode, then enter these lines 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 |
\ endifPress the Escape key to take vim out of Insertion Mode, then press ‘:‘ (colon) followed by ‘x‘ to save the file and exit. Enter this command again:
sudo vim vimrc
… and you’ll see that vim now automatically indents code, displays the cursor position, has syntax highlighting, etc.
Related posts:
- Enabling Terminal’s directory and file color highlighting in Mac OS X
- MySQL 5, PHP 5 and Apache2 configuration on OS X 10.5.* (Leopard)
- Enabling remote access to a MySQL Database Server
- Bash Script to split a single CSV file into multiple files with headers
- Reusing commands with different arguments on a Bash command line
Like this post? Subscribe to the Geekology RSS 2.0 feed!













Simon
March 11th, 2009 at 06:33
by the look of your screenshot you probably want this too:
and it might be worth mentioning that ~/.vimrc is a place to put user specific vim configuration
willem
March 11th, 2009 at 12:04
Thank you, Simon!
D. Starr
March 11th, 2009 at 20:45
Awesome tip thanks!
Mark
May 24th, 2009 at 00:17
Thank you so much for this!!!
bitwonk
June 4th, 2009 at 01:02
You may also need to go into Terminal perferences > Settings > Text and enable “Display ANSI colors”.
Dave
June 29th, 2009 at 04:31
Again. Thanks. This also worked perfectly.
herik
August 25th, 2009 at 06:01
thanks, it works
Matelot
September 8th, 2009 at 19:44
Thanks!
Really simple and helpfull
Dipak
November 2nd, 2009 at 04:18
Thanks a lot! It works
Willem
November 2nd, 2009 at 09:13
Sure, I’m glad you guys found it useful!
Jacques
November 25th, 2009 at 02:57
Thanks so much! This will save me so many headaches. All the other solutions I was finding involved installing SIMBL and other things, which I knew couldn’t have been right because it was for Terminal, and vim access on other machines were still showing syntax highlighting, so I knew it had to be my local vim.
Thanks again!
Senthil
December 7th, 2009 at 12:48
nice. thanks
Sean
December 19th, 2009 at 09:26
That’s fantastic. Thanks.
Dmitry Dulepov (dmitryd) « Enable syntax highlighting and other options in vim on Mac OS X 10.... « Chat Catcher
December 22nd, 2009 at 14:34
[...] 2009-12-22T04:33:47 Enable vim (vi) syntax highlighting on Mac OS X: [link to post] [...]
Helmut Hummel (helhum) « Enable syntax highlighting and other options in vim on Mac OS X 10.... « Chat Catcher
December 22nd, 2009 at 14:35
[...] 2009-12-22T04:33:47 RT @dmitryd: Enable vim (vi) syntax highlighting on Mac OS X: [link to post] [...]
Justin Dorfman
December 30th, 2009 at 19:09
Awesome. Thanks.
Asha
February 5th, 2010 at 05:14
Thanks a lot. Was a great help.