" " 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 :setlocal spell spelllang=en_us map :setlocal nospell "}}} " For moving around split windows"{{{ nmap w nmap W nmap h nmap l "}}} " Buffer Navigation"{{{ map :bprevious map :bnext map :bfirst map :blast "}}} " Maps for Explore"{{{ map e :Explore map :Vexplore "}}}"}}} " " Map for CDing to directory of currently editing file."{{{ " maps the exec command to \fcd " Mnemonic : file change directory map fcd :exec "cd %:p:h" "}}}"}}} " 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# " Undoing in Insert Mode (Control-Z) map 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 =strftime("%c") iab LMODSTMP Last Modified: =strftime("%c") " 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 ccomstuff() autocmd FileType c call cstuff() autocmd FileType cpp call cppstuff() "Common C/C++ hook"{{{ function ccomstuff() set cindent set formatoptions+=croql set formatoptions-=t map :!./a.out "The following mapping puts function comment. Hover over name map \fc F "nyf("ry0f(l"ayf)O/*54A-o"npxoArgs: "apxoReturns: "rpoThrows:See:Bugs:54A-a*/6kA -- endfunction "}}} " C-special hook"{{{ function cstuff() if filereadable("Makefile") set makeprg=make else set makeprg=gcc\ %\ -Wall\ -g endif nmap :!ctags *.c *.h endfunction "}}} " C++-special hook"{{{ function cppstuff() if filereadable("Makefile") set makeprg=make else set makeprg=gcc\ %\ -Wall\ -g endif nmap :!ctags *.cpp *.h 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 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: di to start and ds to stop " * gnupg : " * matchit : To enable reg-ex matching over '%' - aid html " * Matrix Screensaver : :!Matrix " * minibufexpl : mini buffer explorer " * pydoc : :Pydoc foo or pw or pW " (u and Ctrl-r for going front and back) " * scmdiff "{{{ let g:SCMDiffCommand = 'git' map :call SCMDiff() map :set nodiff noremap