Thursday, April 16, 2009

A sample .vimrc file

I use vim to write C/C++ and python programs. It is a very powerful editor for programmers. However before starting to use it, you need to have a customized .vimrc configure file to make vim work the way you like. The following is the .vimrc I'm currently using. It alone can meet my needs of editing C/C++ programs. I will talk about python later.

set nocompatible " use vim defaults
set ls=2 " allways show status line
set tabstop=4 " numbers of spaces of tab character
set shiftwidth=4 " numbers of spaces to (auto)indent
set smarttab
set expandtab
set softtabstop=4
set scrolloff=3 " keep 3 lines when scrolling
set showcmd " display incomplete commands
set hlsearch " highlight searches
set incsearch " do incremental searching
set ruler " show the cursor position all the time
set visualbell t_vb= " turn off error beep/flash
set novisualbell " turn off visual bell
set nobackup " do not keep a backup file
set number " show line numbers
"set ignorecase " ignore case when searching
set noignorecase " don't ignore case
set title " show title in console title bar
set ttyfast " smoother changes
"set ttyscroll=0 " turn off scrolling, didn't work well with PuTTY
set modeline " last lines in document sets vim mode
set modelines=3 " number lines checked for modelines
set shortmess=atI " Abbreviate messages
set nostartofline " don't jump to first character when paging
set whichwrap=b,s,h,l,<,>,[,] " move freely between files
"set viminfo='20,<50,s10,h guifont="Monospace\" lines="50" height =" 50" columns="100" width =" 100" background="light" selectmode="mouse,key,cmd" keymodel=" else" background="dark"> 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif " Filetypes (au = autocmd) au FileType helpfile set nonumber " no line numbers when viewing help au FileType helpfile nnoremap " Enter selects subject
au FileType helpfile nnoremap " Backspace to go back

" When using mutt, text width=72
au FileType mail,tex set textwidth=72
au FileType cpp,c,java,sh,pl,php,asp,py set autoindent
au FileType cpp,c,java,sh,pl,php,asp,py set smartindent
au FileType cpp,c,java,sh,pl,php,asp,py set cindent
"au BufRead mutt*[0-9] set tw=72

" Automatically chmod +x Shell and Perl scripts
"au BufWritePost *.sh !chmod +x %
"au BufWritePost *.pl !chmod +x %

" File formats
au BufNewFile,BufRead *.pls set syntax=dosini
au BufNewFile,BufRead modprobe.conf set syntax=modconf
endif

set autoindent " always set autoindenting on
set smartindent " smart indent

filetype plugin indent on
:fixdel