" 
" Author : Pranesh Srinivasan
" Last Modified: Wednesday 02 July 2008 01:13:54 AM IST
"  
"  
" This file has an elaborate folding scheme. Please do not tamper
" with it.
" 
" If you do not understand folds, just hit zR in escape mode.
 
"Of course, prefer vim settings to vi's
set nocompatible

"Fix the staring incosistency
nmap Y y$

" First some general settings
" I like to know which mode I am in at times
set showmode

"Set mouse, if it is allowed 
set mousemodel=popup

" Turn on syntax if possible."{{{
if has("syntax")
	syntax on
endif
"}}}

" General Settings"{{{"{{{
" A few search related options"{{{
set hlsearch
set incsearch
set gdefault
"}}}

" Next a few indentation options"{{{
set autoindent
set smartindent
"}}}

" set the size of a tab to 4 space"{{{
set tabstop=4
" set the size of an indent
set shiftwidth=4
"}}}
"}}}

" Next some GUI and Rendering Options"{{{
" I can do without the Toolbar, the left and right 
" scrollbars, blah..
set guioptions-=T
set guioptions-=r
set guioptions-=R
set guioptions-=l
set guioptions-=R
" Set lazydraws so that rendering is much faster
" during macros
set lazyredraw
" Set scrolling rules
set scrolloff=3
set sidescrolloff=2
"}}}

" Vim info, history and backup"{{{
"
" Viminfo Settings"{{{
" I like a nice, large Vim info
" '1000 save history for 1000 files
" f1 save marks 
" <500 save at most 500 lines in any yank
" 	which is saved
" /1000 save 1000 lines from command history
set viminfo='1000,f1,<500,:1000,/1000
" set bash history to at most 500 lines in
" the vim session (different from viminfo
set history=500
""}}}
"
" Backups are pretty useful except when the create ~files "{{{
"set backup
"}}}
"
" Vim sessionoptions"{{{
" really awesome
" add resize to the list, so that my resizing
" of various windows is preserved
set sessionoptions+=resize
" note that curdir is already include by default
" store window position as well
" set sessionoptions+=window
"
" Here comes the ultra cool part 
" I have created a project template, by
" resizing various windows, et al. This default
" window setup can be obtained by sourcing the 
" proj.vim from my templates directory
" source ~/.vim/sessions/templates/proj.vim
"}}}
"}}}

" Some particulars about commands and Completion"{{{
set showcmd
" Setting showfulltag, so that C-style coding is
" easier
set showfulltag
"}}}
"
"Allow some cool features of the command completion ex mode"{{{
set wildmenu
" set wildignore+=*.o,*.obj,*~
""}}}"}}}

" Folding and list chars - misc options"{{{
" folding enable
"
if has("folding")
	set foldenable
endif
"}}}

" Matchpairs and Triangular Brackets"{{{
" include triangular brackets in defaults
set matchpairs+=<:>
" what to show when I hit :set list
set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$ 
"}}}"}}}

" Schema - Color, status line, and window title bar"{{{
"
" Colorscheme Mania :)"{{{
" colorscheme evening
" colorscheme desert
" colorscheme inkpot
" colorscheme tolerable
" colorscheme ps_color
" colorscheme professional
" colorscheme candycode
" colorscheme biogoo
if has("gui_running")
	colorscheme desert
else
	colorscheme evening
endif
"}}}

" Status line mania"{{{
" All sorts of status line options to follow
set laststatus=2
"
" Vim Buddy. A late night, will never be lonely again."{{{
" (patched version)
if filereadable(expand("$HOME/.vim/plugin/vimbuddy.vim"))
	set statusline=%F%m%r%h%w\ [format=%{&ff}]\ [ft=%Y]\ [ascii=\%03.3b]\ [hex=\%02.2B]\ [pos=%04l,%04v]\ %{VimBuddy()}
else
	set statusline=%F%m%r%h%w\ [format=%{&ff}]\ [ft=%Y]\ [ascii=\%03.3b]\ [hex=\%02.2B]\ [pos=%04l,%04v]
endif
"}}}

"set statusline+=%=                           " right align
" Of course, I like the ruler there if possible.
set ruler
"}}}

" Nice window title"{{{
if has('title') && (has('gui_running') || &title)
	" start off with a blank string
    set titlestring=
	" file name
    set titlestring+=%f\  
	" flags
    set titlestring+=%h%m%r%w                                         
	" program name
    set titlestring+=\ -\ %{v:progname}                               
    " working directory
    set titlestring+=\ -\ %{substitute(getcwd(),\ $HOME,\ '~',\ '')}
endif
"}}}"}}}

" Set common paths for searching"{{{
set path+=src/
set path+=include/
"}}}

" Filetype plugins"{{{
if has("eval")
    filetype on
    filetype plugin on
    filetype indent on
endif
"}}}

" Commonly Used Maps (No Plugin Maps) and Abbreviations"{{{"{{{"{{{
" For Spell Check Toggling"{{{
map <F8> <Esc>:setlocal spell spelllang=en_us<CR>
map <F9> <Esc>:setlocal nospell<CR>
"}}}

" For moving around split windows"{{{
nmap <s-down>   <c-w>w
nmap <s-up>     <c-w>W
nmap <s-left>   <c-w>h
nmap <s-right>  <c-w>l
"}}}

" Buffer Navigation"{{{
map <M-Left> 	:bprevious<CR>
map <M-Right> 	:bnext<CR>
map <M-Up>		:bfirst<CR>
map <M-Down>	:blast<CR>
"}}}

" Maps for Explore"{{{
map <Leader>e 	:Explore<CR>
map <F3>		:Vexplore<CR>
"}}}"}}}
"
" Map for CDing to directory of currently editing file."{{{

" maps the exec command to \fcd 
" Mnemonic : file change directory
map <leader>fcd :exec "cd %:p:h" <CR>
"}}}"}}}

" Misc Maps"{{{
" To prevent the # from being insertable only at
" the start of a line. I write a good amount of python
" code I find this irritating.
inoremap # X<BS>#
" Undoing in Insert Mode (Control-Z)
map <c-z> <c-o>u
"}}}

" A few abbreviations"{{{
" I type algorithms and Computer Science fairly often."{{{
iab cs Computer Science
iab algo Algorithms
iab algos Algorithms
"}}}

" Timestamping"{{{
" Mnemonic TSTMP
iab TMSTMP <c-r>=strftime("%c")<CR> 
iab LMODSTMP Last Modified: <c-r>=strftime("%c")<CR>

" Search the first 20 lines for Last modified: and update the current datetime.
function! LastMod()
    if line("$") > 20
let l = 20
    else
let l = line("$")
    endif
    exe "1," . l . "g/Last Modified: /s/Last Modified: .*/Last Modified: " .
\ strftime("%c")
endfun

" This auto command will call LastMod function everytime you save a file
autocmd BufWrite *   ks|call LastMod()|'s

"}}}"}}}"}}}

" File Hooks"{{{

" Enable Man default behaviour for clean formatting of man pages"{{{
runtime! ftplugin/man.vim
"}}}

" File Hooks for C and C++ functions follow"{{{
" including a self written macro which maps to \fc

" In the following lines, we enable a macro to attach function comments.
" We also check if there is a Makefile in the Project Directory, and
" accordingly assign the variable make.
" Control+F9 is mapped to Compile
" and Shift+F9 is mapped to running ./a.out
autocmd FileType c,cpp call <SID>ccomstuff()
autocmd FileType c call <SID>cstuff()
autocmd FileType cpp call <SID>cppstuff()

"Common C/C++ hook"{{{
function <SID>ccomstuff()
	set cindent
	set formatoptions+=croql
	set formatoptions-=t
	map <S-F9> <Esc>:!./a.out<CR>
	"The following mapping puts function comment. Hover over name
	map \fc F "nyf("ry0f(l"ayf)O/*<Esc>54A-<Esc>o<Esc>"npxoArgs: <Esc>"apxoReturns: <Esc>"rpoThrows:<CR>See:<CR>Bugs:<CR><Esc>54A-<Esc>a*/<Esc>6kA -- <Esc> 	
endfunction
"}}}


" C-special hook"{{{
function <SID>cstuff()
	if filereadable("Makefile")
		set makeprg=make
	else
		set makeprg=gcc\ %\ -Wall\ -g
	endif
	nmap <M-a> <Esc>:!ctags *.c *.h<CR>
endfunction
"}}}
	
" C++-special hook"{{{
function <SID>cppstuff()
	if filereadable("Makefile")
			set makeprg=make
	else
		set makeprg=gcc\ %\ -Wall\ -g
	endif
	nmap <M-a> <Esc>:!ctags *.cpp *.h<CR>
endfunction
"}}}"}}}"}}}


" Plugins"{{{
" This configuration has a heavy use of plugins. 
" Plugin hunts over two whole months led to this.
"
" Plugin Descriptions"{{{
" We first list and describe the plugins :
" 	
"	* A Browser Plugin (:Browser) for the web :)
"	* C Plugin to complete statments, fill up file templates, etc..
"	* Calendar Plugin with a diary (:Calendar)
"	* ColorScheme Menu Maker plugin, that makes the menus at the top.
"	* A C Reference manual (to be configured).
"	* DrawIt plugin: enables you to draw using arrowkeys and PgUp, etc..
"	* gnupg : A plugin for encrypting and decrypting with the private key.
"	* matchit : To enable reg-ex matching over '%' - aid html 
"	* Matrix Screensaver
"	* minibufexpl : mini buffer explorer
"	* pydoc : enables python documentation in vim
"	* scmdiff : provides a nice interface for cvs/svn/git diffs
"	* scratch : A plugin on the lines of Emacs *scratch* buffer
"	* shell : Enables a shell in a buffer by using <LEADER>sh
"	* sketch : like drawit, but with the mouse.
"	* taglist : A wonderful tags browser using TlistToggle()
"	* vimbuddy : A nice little smiley that sits on the status bar
"	* vimNotes : enables you to take, make and connect notes using Vim
"
"	I only need a mutt interface ;)"}}}
"
" Mapping Descriptions"{{{
" We now map commands, and or set global variables as necessary for each of
" the plugins. Else we list common Usage.

"	* Browser Plugin : Browser
"	* C Plugin : (See the pdf)
"	* Calendar : (:Calendar)
"	* ColorScheme 
"	* A C Reference manual
"	* DrawIt plugin: <Leader>di to start and <Leader>ds to stop
"	* gnupg : 
"	* matchit : To enable reg-ex matching over '%' - aid html 
"	* Matrix Screensaver : :!Matrix
"	* minibufexpl : mini buffer explorer
"	* pydoc : :Pydoc foo or <leader>pw or <leader>pW 
"			  (u and Ctrl-r for going front and back)
"	* scmdiff "{{{
let g:SCMDiffCommand = 'git'
map <C-F3> :call <SID>SCMDiff()<CR>
map <M-F3> :set nodiff<CR>
noremap <unique> <script> <plug>Dh :call <SID>SCMDiff("h")<CR>
"}}}

"	* scratch : A plugin on the lines of Emacs *scratch* buffer"{{{
map <C-d> :Sscratch
"}}}

"	* shell : <Leader>sh
"	* sketch : like drawit, but with the mouse.
"	Mnemonic for Mouse Sketch"{{{
noremap <Leader>ms :call ToggleSketch()<CR>
"}}}
"	* taglist : A wonderful tags browser using TlistToggle()"{{{
map <F2> :TlistToggle<CR>
""}}}
"	* vimbuddy : A nice little smiley that sits on the status bar
"	* vimNotes : enables you to take, make and connect notes using Vim"{{{
let g:VN_DefaultDir = "~/Notes"
let g:VN_filenamestring = "notebk.txt"

" Mnemonic noTes, new, search, new section, link"{{{
map <leader>vns <PLUG>VN_Search 

map <leader>vnn <PLUG>VN_NewFile

map <leader>vnt <PLUG>VM_NewSection

map <leader>vnl <PLUG>VN_OpenHTTPLink

"}}}"}}}"}}}"}}}


" Change from my normal 'marker' fold method to marker for this file.
" vim:set foldmethod=marker:
