August 19, 2011

vimrc

" Filename      : vimrc
" Description   : ViM Configuration File
" Last Modified : 09 Aug 2011, 04:41am

"=============================== a-z ===================================
" FIRST SECTION "
"=======================================================================
set nocompatible " Bram Moolenaar suggests this as the first line of our vimrc
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
    " Use panthogen easily modify the runtime path to include all plugin
    " under the ~/.vim/bundle directory
    " run 'git submodule init && git submodule update'
    " every time a submodule is added.
set cpoptions=aABceFsmq
"             |||||||||
"             ||||||||+-- When joining lines, leave the cursor
"             |||||||       between joined lines
"             |||||||+--- When a new match is created (showmatch)
"             ||||||        pause for .5
"             ||||||+---- Set buffer options when entering the
"             |||||         buffer
"             |||||+----- Write command updates current file name
"             ||||+------ Automatically add <CR> to the last line
"             ||||          when using :@r
"             |||+------- Searching continues at the end of the match
"             |||           at the cursor position
"             ||+-------- A backslash has no special meaning in mappings
"             |+--------- :write updates alternative file name
"             +---------- :read updates alternative file name
set encoding=utf-8 " Sets the character encoding used in VIM
set fileencodings=utf-8 " Character encoding for the file of this buffer
set fileformats=unix,dos,mac " Support all three, in this order
set history=200 " Store 200 history (default is 20)
set noexrc " Don't use local version of .(g)vimrc, .exrc
set termencoding=utf-8 " Encoding used for the terminal
set ttyfast " We have a fast terminal connection


"=============================== a-z ===================================
" GENERAL SETTING "
"=======================================================================
autocmd BufWinEnter *.* silent loadview " Make VIM load view (state) (folds, cursor, etc)
autocmd BufWinLeave *.* mkview " Make VIM save view (state) (folds, cursor, etc)
filetype plugin indent on " Load filetype plugins/indent settings
set autochdir " Always switch to the current file directory
set backspace=indent,eol,start " Make backspace more flexible
set nobackup " No backup files, use modern ways
set clipboard+=unnamed " Share windows clipboard
set hidden " We can change buffers without saving
set iskeyword+=_,$,@,%,# " None of these are word dividers
set mouse=a " Use mouse everywhere
set noerrorbells " Silent please :)
set noswapfile " Do not write annoying swap files
set whichwrap=b,s,<,>,~,[,] " Everything wraps
"             | | | | | | |
"             | | | | | | +-- "]" Insert and Replace
"             | | | | | +---- "[" Insert and Replace
"             | | | | +------ "~" Normal
"             | | | +-------- <Right> Normal and Visual
"             | | +---------- <Left> Normal and Visual
"             | +------------ <Space> Normal and Visual
"             +-------------- <BS> Normal and Visual
set wildmenu " Turn on command line completion wild style
set wildignore=*.dll,*.o,*.obj,*.bak,*.exe,*.pyc,*.swp
                 \*.jpg,*.gif,*.png " Ignore these list file extensions
set wildmode=list:longest " Turn on wild mode huge list
set winaltkeys=no " ALT key combination can be mapped


"=============================== a-z ===================================
" USER INTERFACE "
"=======================================================================
colorscheme wombat256
set background=dark " Assume a dark background
set completeopt=longest,menuone
set cmdheight=1 " Number of screen lines to use for the command-line
set cursorcolumn " Highlight the current column
set cursorline " Highlight current line
set number " Turn on line numbers
set incsearch " Highlight as we type our search phrase
set laststatus=2 " Always show the status line
set lazyredraw " Do not redraw while running macros
set linespace=0 " Don't insert any extra pixel lines betweens characters
set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$
 " Display unprintable characters when we hit :set list
set matchtime=5 " How many tenths of a second to blink matching brackets for
set nohlsearch " Do not highlight searched for phrases
set nostartofline " Leave my cursor where it was
set novisualbell " Don't blink for error messages
set report=0 " Message will be given for most ":" commands
set ruler " Always show current positions along the bottom
set scrolloff=5 " Keep 5 lines (top/bottom) for scope
set sessionoptions=resize,winpos,winsize,buffers,tabpages,folds,curdir,help
set shortmess=aOstT " Shortens messages to avoid all the hit-enter prompts
set showcmd " Show the command being typed
set showmatch " Show matching brackets
set showmode " Display the current mode
set t_Co=256 " ViM can use 256 colors inside Gnome Terminal
set statusline=%1*%m%*%r%h%w%f\[%n]\ [mode:%{&ff}]\ [filetype:%Y]\ %{'['.(&fenc!=''?&fenc:&enc).']'}\ [line:%l/%L]\ [col:%v]\ [%p%%]
    hi User1 term=inverse,bold cterm=inverse,bold ctermfg=red " highlight modified flag in red
set viewoptions=folds,options,cursor,unix,slash
 " Changes the effect of the :mkview commands, better unix / windows compatibility.
syntax on " Syntax highlighting on


"=============================== a-z ===================================
" TEXT FORMATTING "
"=======================================================================
set expandtab " No real tabs please!
set formatoptions=tcrqn " How automatic formatting is to be done
"    |||||
"    ||||+- Recon numbered lists
"    |||+-- gq formats comments (?)
"    ||+--- Insert comment leader (?)) on <CR>
"    |+---- Autowrap COMMENTS using textwidth
"    +----- Autowrap TEXT using textwidth 
set ignorecase " Case insensitive by default
set infercase " Case inferred by default
set nowrap " Do not wrap line
set shiftround " When at 3 spaces, and I hit > ... go to 4, not 5
set shiftwidth=4 " Auto-indent amount when using cindent
set smartcase " If there are caps, go case-sensitive
set softtabstop=4 " When hitting tab or backspace, how many spaces 
                  "should a tab be
set tabstop=8 " Real tabs should be 8, and they will show with set list on
              " session settings  
set textwidth=80 " line length above which to break a line
set wrapmargin=4 " Margin from the right in which to break a line

" reading Ms-Word documents, requires antiword
autocmd BufReadPre *.doc set ro 
autocmd BufReadPre *.doc set hlsearch! 
autocmd BufReadPost *.doc %!antiword "%" 

"=============================== a-z ===================================
" FOLDING "
"=======================================================================
set foldenable " Turn on folding
set foldlevel=50 " Don't autofold anything
set foldmarker={,} " Fold C style code (only use this as default
                   " if you use a high foldlevel)
set foldmethod=manual " Fold manually
set foldopen=block,hor,mark,percent,quickfix,tag " What movements open folds


"=============================== a-z ===================================
" COMPLETION "
"=======================================================================
autocmd FileType c set omnifunc=ccomplete#Complete
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType java setlocal completefunc=javacomplete#Complete
autocmd FileType java setlocal omnifunc=javacomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
set complete=.,w,b,u,t,i " Automatically complete any class, method, or field name
setlocal omnifunc=syntaxcomplete#Complete


"=============================== a-z ===================================
" JAVA "
"=======================================================================
autocmd FileType java runtime! autoload/javacomplete.vim
let java_allow_cpp_keywords=1
let java_comment_strings=1
let java_highlight_all=1
let java_highlight_debug=1
let java_highlight_functions="style"
let java_highlight_java_lang_ids=1
let java_ignore_javadoc=1
let java_mark_braces_in_parens_as_errors=1
    "-------------------------------"
    " COMPILE - FIX ERRORS AND RUN  "
    "-------------------------------"
    autocmd Filetype java set makeprg=javac\ %
    set errorformat=%A%f:%l:\ %m,%-Z%p^,%-C%.%#
    map <F5> :w<CR>:make<CR>:copen<CR>
    map <F6> :cprevious<CR>
    map <F7> :cnext<CR>
    map <F8> :call RunClass()<CR>
        func! RunClass()
                :!java -cp "%:p:h" "%:t:r"
        endfunc

"=============================== a-z ===================================
" MAPPING "
"=======================================================================
let mapleader = ","
nnoremap ; :
nmap <C-a> ggVG                 " Select all
nmap <C-n> :tabnew<CR>          " Open a new tab
imap <C-s> :w<CR>               " Control-s be 'save' as it is in most other editors
map bn :bn<CR>                  " Move to next buffer
map bp :bp<CR>                  " Move to previous buffer
map bd :bd<CR>                  " Delete current buffer
map qq :close<CR>               " Close VIM 
map QQ :q!<CR>                  " Force quit VIM
map FF zf9j                     " Fold 10 lines down
map J <C-f>                     " Page down
map K <C-b>                     " Page up
map S :w<CR>                    " Save
map Q :q<CR>                    " Quit
"--------------------"
" Interact with UNIX "
"--------------------"
map ,e :e ~/.vimrc<CR>          " Open vimrc for modify settings
map <F2> :so $HOME/.vimrc<CR>   " Reload .vimrc
map <F3> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR> " Rebuild ctags database
map <F4> :shell<CR>             " Execute a shell
map ,cd :lcd %:p:h<CR>         " cd to current file directory
    "-----------------------------------"
    " Copy-Paste & Paragraph Formatting "
    "-----------------------------------"
    vmap ,c "+y                     " Copy to other text editors
    vmap ,x "+x                     " Cut to other text editors
    cmap ,v "+gP
    nmap ,v "+gP
    imap ,v <Esc>"+gPa
    map ,lc :%s/\<./\l&/g<CR>       " 1st letter of each word lowercase
    map ,uc :%s/\<./\u&/g<CR>       " 1st letter of each word uppercase
    map ,lf :%s/.*/\l&<CR>          " 1st letter of each line lowercase
    map ,uf :%s/.*/\u&<CR>          " 1st letter of each line uppercase
" ---------------"
" Plugin Mapping "
" ---------------"
nmap nt :NERDTreeToggle<CR>         " Toggle nerd tree file explorer
nmap tt :TagbarToggle<CR>               " Tagbar source code browser
nmap TT :TlistToggle<CR>                " View Taglist, source code browser
nmap <silent> <leader>c :Calendar<CR>   " Open the calendar
nmap <silent> <Leader>t :CommandT<CR>
nmap <silent> <Leader>b :CommandTBuffer<CR>
nmap <silent> <Leader>f :CommandTFlush<CR>
    "-----------------------------"
    " Moving Through Split Window "
    "-----------------------------" 
    map <M-Down> <Esc><C-w>j
    map <M-Up> <Esc><C-w>k
    map <M-Right> <Esc><C-w>l
    map <M-Left> <Esc><C-w>h
"------------------------ "
"  Move Split Window to:  "
"-------------------------"
map tj <C-W>J
map tk <C-W>K
map th <C-W>H
map tl <C-W>L
    "--------------------"
    " Resize Split Window"
    "--------------------"
    nmap <C-Down> <C-W>-<C-W>-
    nmap <C-Up> <C-W>+<C-W>+
    nmap <C-Right> <C-W>><C-W>>
    nmap <C-Left> <C-W><<C-W><


"=============================== a-z ===================================
" ABBREVIATIONS "
"=======================================================================
iab ddtt <C-R>=strftime("%d %b %Y, %I:%M%P")<CR>
 " Insert current date & time
iab psvm public static void main (String[] args ) {
iab sop System.out.println ("


"=============================== a-z ===================================
" CONFIGURE TAGS "
"=======================================================================
autocmd FileType java set tags=/home/foss/Workspace/.tags
set tags=~/.tags


"=============================== a-z ===================================
" GUI SETTINGS "
"=======================================================================
if has("gui_running")
    "colorscheme candycode
    set columns=80
    "set guifont=Tahoma:h10
    "set guioptions-=m
    "set guioptions-=T
    set mousehide " Hide the mouse cursor when typing 
    set lines=25
endif


"=============================== a-z ===================================
" PLUG-IN MANAGEMENT "
"=======================================================================
    "-----------------"
    " == COMMAND-T == "
    "-----------------"
    let g:CommandTMaxFiles=200
    let g:CommandTMaxHeight=10
"-----------------------------"
" === AUTO-COMPLETE-POPUP === "
"-----------------------------"
let g:AutoComplPop_CompleteoptPreview=1
let g:AutoComplPop_Behavior =
\{ 'python' : [ ['\k\{0,}$', "\<C-x>\<C-o>"],
\ ['\k\{0,}$', "\<C-x>\<C-n>"]
\ ],
\ 'css' : [ ['\k\{0,}$', "\<C-x>\<C-o>"],
\ ['\k\{0,}$', "\<C-x>\<C-n>"]
\ ],
\ 'javascript' : [ ['\k\{0,}$', "\<C-x>\<C-o>"],
\ ['\k\{0,}$', "\<C-x>\<C-n>"]
\ ],
\ 'java' : [ ['\k\{0,}$', "\<C-x>\<C-n>"],
\ ['\k\{0,}$', "\<C-x>\<C-u>"]
\ ],
\ 'xml' : [ ['\k\{0,}$', "\<C-x>\<C-n>"],
\ ['\k\{0,}$', "\<C-x>\<C-o>"]
\ ],
\ 'html' : [ ['\k\{0,}$', "\<C-x>\<C-o>"],
\ ['\k\{0,}$', "\<C-x>\<C-n>"]
\ ]
\ }
    "----------------------"
    " === JAVACOMPLETE === "
    "----------------------"
    setlocal completefunc=javacomplete#CompleteParamsInfo
    setlocal omnifunc=javacomplete#Complete
    inoremap <buffer> <C-X><C-U> <C-X><C-U><C-P>
    inoremap <buffer> <C-S-Space> <C-X><C-U><C-P> 
        if has("autocmd")
            autocmd Filetype java setlocal omnifunc=javacomplete#Complete
            autocmd Filetype java setlocal 
        endif
"-------------------"
" === SUPER-TAB === "
"-------------------"
let g:SuperTabContextDefaultCompletionType = "<c-x><c-o>"
let g:SuperTabDefaultCompletionType = "context"
    "--------------"
    " == TAGBAR == "
    "--------------"
    let g:tagbar_userarrows = 1
    let g:tagbar_width = 25
"-----------------"
" === TAGLIST === "
"-----------------"
let Tlist_Enable_Fold_Column = 1 " Do show folding tree
let Tlist_Show_One_File = 1 "Show tags for the current buffer only
let Tlist_Exit_OnlyWindow = 1 " If you are the last, exit ViM
let Tlist_File_Fold_Auto_Close = 0 " Fold closed other trees
let Tlist_Sort_Type = "name" " Order by name
let Tlist_WinWidth = 25 " 25 columns wide

set secure " The Vim documentation suggests adding this as the last line of our vimrc

"-------------------------- vimrc end here -----------------------------

"=============================== a-z ===================================
" PLUGIN LIST "
"=======================================================================
" Ant_menu              : http://www.vim.org/scripts/script.php?script_id=155
" AutoCompletePop       : http://vim.sourceforge.net/scripts/script.php?script_id=1879
" BufferExplorer        : http://www.vim.org/scripts/script.php?script_id=42
" Calendar              : http://vim.sourceforge.net/scripts/script.php?script_id=52
" ColorSamplePack       : http://www.vim.org/scripts/script.php?script_id=625
" Command-T             : https://wincent.com/products/command-t  
" CSApprox              : http://www.vim.org/scripts/script.php?script_id=2390
" Fugitive              : http://www.vim.org/scripts/script.php?script_id=2975
" JavaComplete          : http://vim.sourceforge.net/scripts/script.php?script_id=1785
" L9                    : http://www.vim.org/scripts/script.php?script_id=3252
" NERDTree              : http://www.vim.org/scripts/script.php?script_id=1658
" OmniCppComplete       : http://www.vim.org/scripts/script.php?script_id=1520
" Pathogen              : http://www.vim.org/scripts/script.php?script_id=2332 
" Solarized             : http://www.vim.org/scripts/script.php?script_id=3520
" SuperTab              : http://www.vim.org/scripts/script.php?script_id=1643
" Tagbar                : http://www.vim.org/scripts/script.php?script_id=3465
" Taglist               : http://www.vim.org/scripts/script.php?script_id=273
" UpAndDown             : http://www.vim.org/scripts/script.php?script_id=2586

No comments:

Post a Comment