Posted by: Tharindu | June 16, 2010

How to add Syntax Highlighting to Default Mac Terminal

I was wondering why Mac Terminal doesn’t have nice color highlighting that all other Linux based OSs have. Suddenly realized that it should be enabled with few little things to get it done on Mac OS. Follow the few steps to make it highlighted. Before it was enabled my Mac terminal didn’t look any better as my Ubuntu terminal. It was like below.

1. Create a file named .profile if it doesn’t already exists. Add the following line for that file.

alias ls='ls -G'

This will add higlighting when you use, ls commands to list files and directories, better than looking at black color all the time.

2. Do the following to add highlighting for vi editor.

:~ cd /usr/share/vim/
:~ sudo vim vimrc

Add the following code after the line with ‘set backspace=2’

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

Save the file with Esc + :wq. Now your vi editor will show source files with some highlighting as well.

OK. Now it looks far better with some colors after this.

Advertisements

Responses

  1. Thanks Tharindu for this post!!

    Like

  2. Thank you for this post! My terminal looks better now:)

    Like


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: