Conor Mac Aoidh
http://macaoidh.name
conor@macaoidh.name
 
« Tá an Rialtas Seo Dár dTréigean Gan Dabht
Finally Finished »

OS X VIM Syntax Highlighting

Posted Jun 12th, 2010 by Conor

Syntax highlighting isn’t enabled by default on OS X, though it’s easy enough to set it up, and a few other small enhancments at the same it.

Start by executing this command:

cd /usr/share/vim && sudo vim vimrc

After entering your password press i to enter insertion mode and add the following lines after the line set backspace=2:

set showmatch           " automatically show matching brackets
set binary noeol        " do NOT put a carriage return at the end of the last line
set backspace=indent,eol,start  " make that backspace key work the way it should
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

The lines above add syntax highlighting and a few other useful things. The line set binary noeol is very important for web developers. For example if you are programming in PHP and you leave a space outside the closing ?> it will cause http headers to be needlessly sent. That line prevents that from happening.

Well that's it if you press ESC then type :wq you will return to the terminal. Try editing some files again and the highlighting should be enabled.

4 Responses to “OS X VIM Syntax Highlighting”

  • Kae Verens on 12 Jun 2010 at 12:00 pm

    The closing ‘?>’ in PHP is optional. I leave it out, myself, so never have that header problem.

    You might also consider adding code-folding:

    set foldmethod=marker
    set foldmarker={,}
    set foldtext=substitute(getline(v:foldstart),’\\\t’,'\ \ ‘,’g')

  • Conor on 13 Jun 2010 at 8:26 pm

    hmm, I don’t know if I like code-folding… I find it kind of annoying – don’t know why though!

  • rodrigoeiras.eti.br on 29 Jun 2010 at 6:55 pm

    Pequenos ajustes de conforto do Debian “Lenny”…

    I found your entry interesting thus I’ve added a Trackback to it on my weblog :) …

  • Conor on 30 Jun 2010 at 6:01 pm

    Cool, quite an interesting post actually; I got Google to translate it for me! Must figure out how to do that on OS X as my terminal at the moment is monochromatic!

Trackback URI | Comments RSS

Leave a Reply



Conor's Blog is powered by Wordpress | Template design by Conor Mac Aoidh