Sunday, 15 March 2015

Configuring VIM/GVIM through .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, while on Windows systems it is named _vimrc.

You can customize Vim by putting suitable commands in your vimrc. Here is a list of some useful commands and its usage:

"----- General commands

syntax on                    " turns syntax highlighting on
set number                 " (nu) Show number on the Left most side
set cursorline            " Highlight the horizontal line of cursor 
set cursorcolumn       " Highlight the vertical line of cursor
set tabpagemax=100   " Maximum Number of Tabs that can be open using 'gvim -p *'
set hlsearch                 " (hls) highlights all instances of the last searched string
set ruler                     " (ru) show the cursor position at all times
set showcmd              " (sc) display an incomplete command in the lower right
set incsearch               " do incremental searching
set nocompatible        " (cp) use Vim defaults (much better)
set history=1000         " (hi) keep 1000 lines of command history
set textwidth=80         " (tw) number of columns before an automatic line break is inserted (see formatoptions)


"----- Tab and shift related commands

set formatoptions=croq   " (fo) influences how vim automatically formats text
set expandtab                  insert space characters whenever the tab key is pressed
set tabstop=2                  " (ts) control the number of space characters that will be inserted when the tab key is pressed.  Here 2 space will be inserted when tab is pressed.
set shiftwidth=2               " (sw) To change the number of space characters inserted for indentation, autoindent (aswell as << and >>). Here 2 space will be inserted for indentation.
set smarttab                    " (sta) 'shiftwidth' used in front of a line, but 'tabstop' used otherwise
set backspace=indent,eol,start  " (bs) allows backspacing beyond starting point of insert mode, indents and line breaks


"-----Pair matching commands

set showmatch             " (sm) briefly jump to matching bracket when inserting one
set mps=(:),{:},[:],<:>  " allow the match pairs operation (%) to work with '=' and ';'


"-----Different indent-----

set autoindent      " (ai) turn on auto-indenting (great for programers)
set copyindent     " (ci) when auto-indenting, use the indenting format of the previous line
"autowriteall as 'autowrite', but works with more commands
set aw
set awa
set ar            "autoread
set si             "smart indent

No comments:

Post a Comment