Inspired by one my friend’s facebook status which says…”Laziness is a virtue which assists U in doing a job in minimum possible time with maximum possible efficiency !!” , I decided to customize my vim editor to implement features like ctrl+c, ctrl+v, autocomplete, autoindent, single key compile and run etc. to get a “true” IDE

First of all install SuperTab , this extension provides a functionality similar to auto-complete, and for my purposes, infact it improves it. Whenever you are typing a word/variable if you hit tab it will find the nearest match and/or display a list of possible completions.

Now create a .vimrc file if it is not present already in home directory. I’m posting my .vimrc file which is properly commented so that you can modify it in accordance to yourself.

Note that the comment tags are created in vimrc files using the ” (quote) character instead of the more usual # or //. Also during mapping of key “+y etc. represents the key mapped and is NOT a comment.

Here’s my .vimrc file ::

"tab size
set ts=4

"indentation width
set sw=4

"c like indentation
set cindent


"autocomplete menu
set wildmenu
set wildmode=list:longest,full
set mouse=a

"compiling using F3
map <F3> : call CompileGcc()<CR>
func! CompileGcc()
  exec "w"
  exec "!gcc % -o %<"
endfunc

"compile and execute using F9
map <F9> :call CompileRunGcc()<CR>
func! CompileRunGcc()
  exec "w"
  exec "!gcc % -o %<"
  exec "! ./%<"
endfunc

"autocomplete Parenthesis
"When you type an open brace, this will automatically
"insert a closing brace on the same line, after the cursor.
"If you quickly hit Enter after the open brace, (to begin
"a code block), the closing brace will be inserted on the
"line below the cursor. If you quickly press the open brace
"key again after the open brace, Vim won't insert anything extra,
" you'll just get a single open brace. Finally, if you quickly
"type an open and close brace, Vim will not do anything special.
inoremap {      {}<Left>
inoremap {<CR>  {<CR>}<Esc>O
inoremap {{     {
inoremap {}     {}

inoremap (      ()<Left>
inoremap (<CR>  (<CR>)<Esc>O
inoremap ((     (
inoremap ()     ()

inoremap [      []<Left>
inoremap [<CR>  [<CR>]<Esc>O
inoremap [[     [
inoremap []     []

"mapping some more keys ::

"CTRL-X is cut
vnoremap <C-X> "+x

"CTRL-C is copy
vnoremap <C-C> "+y

"CTRL-V is paste
vnoremap <C-V> "+gP

"to paste blockwise, uses paste.vim autoload script
exe 'inoremap <script> <C-V>' paste#paste_cmd['i']
exe 'vnoremap <script> <C-V>' paste#paste_cmd['v']

" CTRL-A is Select all
noremap <C-A> gggH<C-O>G
inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
cnoremap <C-A> <C-C>gggH<C-O>G
onoremap <C-A> <C-C>gggH<C-O>G
snoremap <C-A> <C-C>gggH<C-O>G
xnoremap <C-A> <C-C>ggVG

" Use CTRL-Q to do what CTRL-V used to do
noremap <C-Q>  <C-V>
Advertisements