Thursday, February 25, 2010

Sample vimrc file

The vimrc file contains optional runtime configuration settings to initialize Vim when it starts. On Unix based systems, the file is named .vimrc

Here is a sample .vimrc file I use.


"set smarttab       " When on, a in front of a line inserts blanks according to shiftwidth
set showmode        " Show the current mode
set showcmd         " display incomplete commands
set showmatch       " show matching braces,
set hlsearch        " highlight searches
"set title          " show title in console title bar
set laststatus=2    " always show status line
set ic              " case insensitive search : use set noic to turn it off

set nocompatible    " This setting prevents vim from emulating the original vi's bugs and limitations.

set autoindent
set smartindent
"   The first setting tells vim to use autoindent (that is, use the current line's indent level to set the indent level of new lines). The second makes vim attempt to intelligently guess the indent level of any new line based on the previous line, assuming the source file is in a C-like language. Combined, they are very useful in writing well-formatted source code.

set tabstop=2

set shiftwidth=2
"  The first setting sets up 2-space tabs, and the second tells vi to use 2 spaces when text is indented (auto or with the manual indent adjustmenters.)

set showmatch
"    This setting will cause the cursor to very briefly jump to a brace/parenthese/bracket's match whenever you type a closing or opening brace/parenthese/bracket. I've had almost no mismatched-punctuation errors since I started using this setting.

set vb t_vb=
"This setting prevents vi from making its annoying beeps when a command doesn't work. Instead, it briefly flashes the screen -- much less annoying.

set ruler
"    This setting ensures that each window contains a statusline that displays the current cursor position.


set incsearch
"    With this nifty option, vim will search for text as you enter it. For instance, if you type /bob to search for bob, vi will go to the first b after you type the b, to the first bo after you type the o, and so on. It makes searching much faster, since if you pay attention you never have to enter more than the minimum number of characters to find your target location. Make sure that you press Enter to accept the match after vim finds the location you want.

"set virtualedit=all
"    By default, vim doesn't let the cursor stray beyond the defined text. This setting allows the cursor to freely roam anywhere it likes in command mode. It feels weird at first but is quite useful.


set tags=/tags,./tags

set showfulltag         " Get function usage help automatically

""""""""""""" Highlight following in all files """"""""""""""""""""""
hi TODO ctermfg=red ctermbg=blue term=bold
syntax match TODO /TODO/




""""""""""""""""""""""""""""""""""""""""""
"        Use Cscope within Vi                        "

""""""""""""""""""""""""""""""""""""""""""" Refer http://vim.wikia.com/wiki/Cscope for more details

if has('cscope')
  set cscopetag cscopeverbose

  if has('quickfix')
    set cscopequickfix=s-,c-,d-,i-,t-,e-
  endif

  cnoreabbrev csa cs add
  cnoreabbrev csf cs find
  cnoreabbrev csk cs kill
  cnoreabbrev csr cs reset
  cnoreabbrev css cs show
  cnoreabbrev csh cs help

  command -nargs=0 Cscope cs add $VIMSRC/src/cscope.out $VIMSRC/src
endif
""""""""""""""""""""""""""""""""""""""""""

""""""""""""""""""""""""""""""""""""""""""
"               Mappings                 "
""""""""""""""""""""""""""""""""""""""""""
" Keyboard mappings
map :previous  " map F1 to open previous buffer
map :next      " map F2 to open next buffer
map :setl noai nocin nosi inde= " Disabling auto indent for the current file



No comments: