Babylon Candle: Ubuntu: Highlight me Vim

Sunday, December 23, 2007

Ubuntu: Highlight me Vim

Vim (Vi Improved) gives you many features over that of the standard Vi feature set such, as syntax highlighting, incremental searching, bracket matching and many others. Here's how to install Vim for Ubuntu:

1. Run sudo apt-get install vim from a command prompt.
2. Copy the the default vimrc file from /etc/vim to your home directory with with the name .vimrc

cp /etc/vim/vimrc ~/.vimrc

3. " denote commented features. Uncomment any features you want to turn on. To turn on syntax highlighting change "syntax on to syntax on.

4. Open a java file to see the highlighting in action:

vim yourfile.java



5. If you get the following error:

E319: Sorry, the command is not available in this version: syntax on

it means that you haven't installed vim properly and that you are using tinyVim which, comes standard with Ubuntu. Install Vim as per Step1 again and look out for any errors.

The following is a list of features I use:


" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim

" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
syntax on

" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
set background=dark

" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
set showcmd " Show (partial) command in status line.
set showmatch " Show matching brackets.
set ignorecase " Do case insensitive matching
set smartcase " Do smart case matching
set incsearch " Incremental search
set autowrite " Automatically save before commands like :next and :make
set hidden " Hide buffers when they are abandoned
set mouse=a " Enable mouse usage (all modes) in terminals

" Source a global configuration file if available
" XXX Deprecated, please move your changes here in /etc/vim/vimrc
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif

"this line is a comment .... one which begins with double-quotes
" The best is the bold font, try all of these and pick one....
set guifont=8x13bold
"set guifont=9x15bold
"set guifont=7x14bold
"set guifont=7x13bold
"
" Highly recommended to set tab keys to 4 spaces
set tabstop=4
set shiftwidth=4
"
" The opposite is 'set wrapscan' while searching for strings....
set nowrapscan
"
" The opposite is set noignorecase
set ignorecase
set autoindent
"
" You may want to turn off the beep sounds (if you want quite) with visual bell
set vb

0 comments: