" vim: set foldmarker={,} foldlevel=3 foldmethod=marker:

autocmd VimEnter * echo "abcdw's vimrc version: 0.3-r1"
" Notes {{{
"   ***********************************************************************   "
"   This is the personal .vimrc file of Andrew Tropin.                        "
"   You can find me at http://github.com/abcdw                                "
"   While much of it is beneficial for general use, I would                   "
"   recommend picking out the parts you want and understand.                  "
"   ***********************************************************************   "

    " Tips {
        " Hotkeys {
        " gx - go url under cursor
        " }
    " }
    " Todo {
        " TODO: fix ; and : problem
        " TODO: add google function
        " TODO: spell checking and synonyms
        " TODO: project managment exvim MyProject
        " TODO: prepare and cleanup configs {
        " write comments
        " write README about install and add screenshots
        " }
    " }
" }}}

" "General settings" {
    " Basic {{
        " Various stuff {
            syntax on
            set nocompatible
            set mouse=a
            set langmenu=en
            set helplang=ru
            set fileencodings=utf-8
            set linespace=1 " add some line space for easy reading
            set cursorline
            set ttyfast
            let g:EclimCompletionMethod = 'omnifunc'
        " }
        " Files {
            set encoding=utf-8
            set fileencoding=utf-8
            set fileencodings=utf-8,ucs-bom,cp1251
            set fileformat=unix
            set fileformats=unix,dos,mac
        " }
        " Behavior {
            set backspace=indent,eol,start " Set for maximum backspace smartness"
            set scrolloff=3 " don't scroll any closer to top/bottom
            " set sidescrolloff=999 " don't scroll any closer to left/right
            set sidescrolloff=15 " don't scroll any closer to left/right
            set listchars=tab:▸\ ,trail:·,nbsp:+,eol:¶,nbsp:&,extends:>,precedes:>,conceal:~
            set list
            set display+=uhex " Show unprintables as <xx>
            set display+=lastline
            " set nolazyredraw
            set number
            set autoread
            set autowrite
            " set autochdir
            set virtualedit=block
            set splitbelow
            set splitright
            set gdefault
            set keywordprg=:help
            set spelllang=ru_yo,en
            " set spell
            set nojoinspaces

            autocmd FilterWritePre * if &diff | setlocal wrap< | endif
            autocmd VimEnter * nested call SetupCtrlP()
            if has("autocmd")
              au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
                    \| exe "normal! g'\"" | endif
            endif
            "au BufWinLeave * mkview
            "au BufWinEnter * silent loadview
            "au FocusLost * :wa
            "augroup reload_vimrc " {
                "autocmd!
                "autocmd BufWritePost $MYVIMRC source $MYVIMRC
            "augroup END " }

            augroup helpfiles
             au!
             "au BufRead,BufEnter */doc/* wincmd L
             au BufRead */doc/* wincmd L
            augroup END
        "}
        " Tab and indent {
            set tabstop=4
            set shiftwidth=4
            set shiftround
            set softtabstop=4
            set expandtab
            set smarttab
            set autoindent
            set smartindent
            set cindent
        " }
        " Line wraping {
            " set textwidth=79
            set wrap
            set linebreak " Only wrap on characters in `breakat`
            if has('multi_byte')
                let &showbreak = '↳ '
            else
                let &showbreak = '> '
            endif
        " }
        " Search {
            set showmatch
            set hlsearch
            set incsearch
            set ignorecase
            set smartcase
        " }
        " Status bar and command line settings {
            set cmdheight=1         " Less Hit Return messages
            set laststatus=2        " Always show status bar
            "set report=0            " Always report line changes for : commands
            "set ruler               " Show cursor location
            set shortmess=aoOtT     " Abbreviate the status messages
            "set showmode            " Show mode I'm in
            set showcmd             " Show command I'm typing
            "set statusline=%<%f%h%m%r%=format=%{&fileformat}\ file=%{&fileencoding}\ enc=%{&encoding}\ %b\ 0x%B\ %l,%c%V\ %P
            set timeoutlen=500
        " }
        " Command line completion {
            set wildchar=<TAB>      " Character to start command line completion
            set wildmenu            " Enhanced command line completion mode
            set wildmode=longest:full,full

            " set wildignore+=*/.git/*,*/.hg/*,*/.svn/*
            set wildignore+=*.o,*.obj,*.pyc,*.pyo,*.pyd,*.class,*.lock
            set wildignore+=*.png,*.gif,*.jpg,*.ico
            set wildignore+=.git,.svn,.hg
        " }
        " Backup,Undo,Swap {
            if isdirectory($HOME . '/.vim/backup') == 0
                silent !mkdir -p ~/.vim/backup >/dev/null 2>&1
            endif
            set backupdir-=.
            set backupdir+=.
            set backupdir-=~/
            set backupdir^=~/.vim/backup/
            set backupdir^=./.vim-backup/
            set backup
            " Prevent backups from overwriting each other. The naming is weird,
            " since I'm using the 'backupext' variable to append the path.
            " So the file '/home/docwhat/.vimrc' becomes '.vimrc%home%docwhat~'
            autocmd BufWritePre * nested let &backupext = substitute(expand('%:p:h'), '/', '%', 'g') . '~'

            if isdirectory($HOME . '/.vim/swap') == 0
                silent !mkdir -p ~/.vim/swap >/dev/null 2>&1
            endif
            set directory=./.vim-swap//
            set directory+=~/.vim/swap//
            set directory+=~/tmp//
            set directory+=.

            set viminfo+=n~/.vim/viminfo

            if exists("+undofile")
                " undofile - This allows you to use undos after exiting and restarting
                " This, like swap and backups, uses .vim-undo first, then ~/.vim/undo
                " :help undo-persistence
                if isdirectory($HOME . '/.vim/undo') == 0
                    silent !mkdir -p ~/.vim/undo > /dev/null 2>&1
                endif
                set undodir=./.vim-undo//
                set undodir+=~/.vim/undo//
                set undofile
                set undolevels=1000 " maximum number of changes that can be undone
                set undoreload=10000 " maximum number lines to save for undo on a buffer reload
            endif
        " }
    " }}

    " (re)Maps {{
        let g:mapleader = ' '
        map <C-c> <C-[>
        " map <space> <leader>
        " vmap <space> <leader>
        " map <space><space> :
        " vmap <space><space> :
            " Some useful maps {
                "imap ii <Esc>
                "nnoremap / /\v
                "vnoremap / /\v " allows use perl regexp in search patterns
                " strip trailing whitespaces
                nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
                " select pasted test
                nnoremap <leader>v V`]
                " Keep the cursor in place while joining lines
                nnoremap J mzJ`z
                nnoremap <tab> %
                vnoremap <tab> %

                " Heresy
                " inoremap <c-a> <esc>I
                " inoremap <c-e> <esc>A
                " cnoremap <c-a> <home>
                " cnoremap <c-e> <end>
                " Keep search matches in the middle of the window.
                nnoremap n nzzzv
                nnoremap N Nzzzv
                nnoremap <esc><esc> :<c-u>set nohlsearch<cr>
                nnoremap / :<C-u>set hlsearch<cr>/
                nnoremap ? :<C-u>set hlsearch<cr>?
                nnoremap * :<C-u>set hlsearch<cr>*
                nnoremap # :<C-u>set hlsearch<cr>#

                " Same when jumping around
                nnoremap g; g;zz
                nnoremap g, g,zz
                nnoremap <c-o> <c-o>zz
                nnoremap <c-i> <c-i>zz

                " Easier to type, and I never use the default behavior.
                noremap H ^
                noremap L $
                vnoremap L g_

                noremap j gj
                noremap k gk
                noremap gj j
                noremap gk k

                nnoremap ; :
                imap jj <Esc>o<Esc>
                imap kk <Esc>k
                imap ;; <Esc>A;<Esc>o


                nnoremap <leader>\ :call ToggleNERDTreeAndTagbar()<CR>
                map <leader>ev <C-w><C-v><C-l>:e! $MYVIMRC<CR>
                map <leader>cd :cd %:p:h<CR>:pwd<CR>

                nnoremap <F2> :set invpaste paste?<CR>
                set pastetoggle=<F2>
                " <F2> setting paste mode

                nnoremap <silent> <leader>h :set invhlsearch<CR>
                " disable search highlight
                comm! W exec 'w !sudo tee % > /dev/null' | e!
                " sudo write
                vmap < <gv
                vmap > >gv
                " prevents leaving visual mode after indenting
                map <leader>os :FollowSymlink<CR>
                map <leader>, :w<CR>
                map <leader>bd :bdelete<CR>
                map <leader>q :bdelete<CR>
            " }

        " Disabling arrows {
            imap <left> <nop>
            imap <right> <nop>
            imap <up> <nop>
            imap <down> <nop>
            nmap <left> <nop>
            nmap <right> <nop>
            nmap <up> <nop>
            nmap <down> <nop>
            map <left> <nop>
            map <right> <nop>
            map <up> <nop>
            map <down> <nop>
        " }

        " Splits navigation {
            "nnoremap <leader>v <C-w>v<C-w>l
            "nnoremap <leader>s <C-w>s
            if has('nvim')
                nmap <bs> :<c-u>TmuxNavigateLeft<cr>
            endif
            nnoremap <C-h> <C-w>h
            nnoremap <C-j> <C-w>j
            nnoremap <C-k> <C-w>k
            nnoremap <C-l> <C-w>l
        " }
        " Abbreviations {
            iab UD <BS>Update <C-R>=strftime("%F")<CR>:<CR><Tab>
        " }
    " }}
    " Functions {{
        function! s:MyFollowSymlink() "{
            silent! let s:fname = resolve(expand('%:p'))
            silent! bwipeout
            silent! exec "edit " .s:fname
            " TODO: prevent windows closing
        endfunction
        command! FollowSymlink call s:MyFollowSymlink()

        " augroup followsymlink
            " autocmd!
            " autocmd BufReadPost * FollowSymlink
        " augroup END
        "}

        function! SetupCtrlP() "{
          if exists("g:loaded_ctrlp") && g:loaded_ctrlp
            augroup CtrlPExtension
              autocmd!
              autocmd FocusGained * nested CtrlPClearCache
              autocmd BufWritePost * nested CtrlPClearCache
            augroup END
          endif
      endfunction "}
        function! ToggleNERDTreeAndTagbar() "{
            let w:jumpbacktohere = 1
            " Detect which plugins are open
            if exists('t:NERDTreeBufName')
                let nerdtree_open = bufwinnr(t:NERDTreeBufName) != -1
            else
                let nerdtree_open = 0
            endif
            let tagbar_open = bufwinnr('__Tagbar__') != -1

            " Perform the appropriate action
            if nerdtree_open && tagbar_open
                NERDTreeClose
                TagbarClose
            elseif nerdtree_open
                TagbarOpen
            elseif tagbar_open
                NERDTree
            else
                NERDTree
                TagbarOpen
            endif

            " Jump back to the original window
            for window in range(1, winnr('$'))
                execute window . 'wincmd w'
                if exists('w:jumpbacktohere')
                    unlet w:jumpbacktohere
                    break
                endif
            endfor
        endfunction "}
        function! FindDjangoSettings2() "{
            if strlen($VIRTUAL_ENV) && has('python')
                let django_check = system("pip freeze | grep -q Django")
                if v:shell_error
                    " echo 'django not installed.'
                else
                    " echo 'django is installed.'
                    let output = system("find $VIRTUAL_ENV \\( -wholename '*/lib/*' -or -wholename '*/install/' \\) -or \\( -name 'settings.py' -print0 \\) | tr '\n' ' '")
                    let outarray= split(output, '[\/]\+')
                    let module = outarray[-2] . '.' . 'settings'
                    let syspath = system("python -c 'import sys; print sys.path' | tr '\n' ' ' ")
                    " let curpath = '/' . join(outarray[:-2], '/')
                    execute 'python import sys, os'
                    " execute 'python sys.path.append("' . curpath . '")'
                    " execute 'python sys.path.append("' . syspath . '")'
                    execute 'python sys.path = ' . syspath
                    execute 'python os.environ.setdefault("DJANGO_SETTINGS_MODULE", "' . module . '")'
                endif
            endif
        endfunction "}
    " }}
" }

" "Vundle" Package manager {

filetype off

if executable("git")

    " "Installing"  "{{{

        if !isdirectory(expand("~/.vim/bundle/vundle"))
            echomsg "******************************"
            echomsg "Installing Vundler..."
            echomsg "******************************"
            !mkdir -p ~/.vim/bundle && git clone git://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
            let s:bootstrap=1
        endif

        set rtp+=~/.vim/bundle/vundle/
        call vundle#rc()

        if exists("s:bootstrap") && s:bootstrap
            unlet s:bootstrap
            BundleInstall
            quit
        endif

    " }}}
    " "Bundles and configs" {2

        " General {
            Bundle 'gmarik/vundle'
            " < Vundle - vim package manager > {
            " }
            Bundle 'lilydjwg/colorizer'
            " < Colorize all text in form #rrggbb & #rgb > {
                 "nmap <leader>tc <Plug>Colorizer
            " }
            Bundle 'mtth/scratch.vim'
            " < Unobtrusive scratch window > {
                "gs gS hotkeys
                nnoremap <leader>S :Scratch<CR>
            "}
            Bundle 'Raimondi/delimitMate'
            " < Automatic closing of quotes, brackets, etc > {
                let g:delimitMate_expand_cr = 2
                let g:delimitMate_expand_space = 1
                let g:delimitMate_expand_inside_quotes = 1
                let g:delimitMate_balance_matchpairs = 1
                let g:delimitMate_jump_expansion = 1
                au FileType python let b:delimitMate_nesting_quotes = ['"']
            " }
            Bundle 'mattn/gist-vim'
            " < Vimscript for creating gists (http://gist.github.com) > {
                let g:gist_update_on_write = 2
                let g:gist_clip_command = 'xclip -selection clipboard'
                let g:gist_detect_filetype = 1
                let g:gist_open_browser_after_post = 1
                let g:gist_update_on_write = 2
                " Only :w! updates a gist
            " }
            Bundle 'mattn/webapi-vim'
            " < Auxiliary library > {
            " }
            Bundle 'buddhavs/vim-tasklist'
            " < TO DO-finder > {
                nmap <Leader>tl <Plug>TaskList
            "}
            Bundle 'Gundo'
            " < Undo tree >{
                map <leader>gt :GundoToggle<CR>
            " }
            Bundle 'lyokha/vim-xkbswitch'
            " < Automatic layout switcher > {
                let g:XkbSwitchEnabled = 1
                "let g:XkbSwitchIMappingsSkipFt = ['tex'] " need for latex-suite
                let g:XkbSwitchLib = '/usr/local/lib/libxkbswitch.so'
                " if has("unix")
                    " let s:uname = system("uname -s")
                    " if s:uname == "Darwin\n"
                        " let g:XkbSwitchLib = '/usr/local/lib/libxkbswitch.dylib'
                    " endif
                " endif
                " let g:XkbSwitchIMappings = ['ru(typewriter)']
            " }
            Bundle 'scrooloose/nerdtree'
            " < File system explerer >{
                map <leader>nt :NERDTreeToggle<CR>
                let NERDTreeIgnore=['\.pyc$', '\~$']
            " }
            Bundle 'godlygeek/tabular'
            " < Alignment plugin > {
            " }
            Bundle 'SirVer/ultisnips'
            " < Snippets engine > {
                let g:UltiSnipsExpandTrigger="<tab>"
                let g:UltiSnipsJumpForwardTrigger="<tab>"
                let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
                let g:UltiSnipsEditSplit="horizontal"
            " }
            Bundle 'honza/vim-snippets'
            " < Snippets for ultisnips > {
            " }
            Bundle 'luochen1990/rainbow'
            " < Rainbow Parentheses > {
                " let g:rainbow_active = 1
                map <leader>rt :RainbowToggle<CR>
            " }
            Bundle 'matchit.zip'
            " < Extended matching with "%" > {
            " }
            " Bundle 'kien/ctrlp.vim'
            " < Fuzzy file, buffer, tag finder > {
                let g:ctrlp_cmd = 'CtrlPMRUFiles'
                let g:ctrlp_match_window = 'bottom,order:btt,min:1,max:10,results:100'
                let g:ctrlp_switch_buffer = 'Et'
                let g:ctrlp_working_path_mode = 'ra'
                let g:ctrlp_arg_map = 1
                let g:ctrlp_extensions = ['mixed', 'buffertag']
                let g:ctrlp_reuse_window = 'netrw\|help\|quickfix'

                " TODO: task-list
            " }

            Bundle 'wesQ3/vim-windowswap'
            " < Easy window swapping > {
                let g:windowswap_map_keys = 0 "prevent default bindings
                nnoremap <silent> <leader>yw :call WindowSwap#MarkWindowSwap()<CR>
                nnoremap <silent> <leader>pw :call WindowSwap#DoWindowSwap()<CR>
                nnoremap <silent> <leader>sw :call WindowSwap#EasyWindowSwap()<CR>
            " }

            Bundle 'xolox/vim-misc'
            Bundle 'xolox/vim-notes'
            " < Easy notes plugin > {
                let g:notes_directories = ['~/Documents/notes']
            " }

        " }
        " Developing {
            Bundle 'majutsushi/tagbar'
            " < Browsing the tags of source code files > {
                nmap <leader>tb :TagbarToggle<CR>
                " let g:tagbar_autofocus = 1
                " let g:tagbar_iconchars = ['▸', '▾']
                let g:tagbar_iconchars = ['+', '-']
                let g:tagbar_sort = 0
                " let g:tagbar_left=1
                "let g:tagbar_autoclose = 1
            " }
            Bundle 'scrooloose/nerdcommenter'
            " < Just commenter utility > {
            " TODO: see alternative https://github.com/tomtom/tcomment_vim

                let g:NERDSpaceDelims = 1
                let g:NERDRemoveExtraSpaces = 1
                let g:NERDCustomDelimiters = {
                      \ 'htmldjango': { 'left': '{#', 'right': '#}' }
                      \ }
            " }
            Bundle 'xuhdev/SingleCompile'
            " < Comile or run a single source file > {
                " nmap <leader>ll :SCCompile<CR>
                " nmap <leader>lv :SCCompileRun<CR>
                autocmd Filetype cpp nmap <buffer> <leader>ll :SCCompileAF -std=c++0x <CR>
                autocmd Filetype cpp nmap <buffer> <leader>lv :SCCompileRunAF -std=c++0x <CR>
                autocmd Filetype java nmap <buffer> <leader>ll :ProjectBuild <CR>
                autocmd Filetype java nmap <buffer> <leader>lv :ProjectRun <CR>
                autocmd Filetype cs nmap <buffer> <leader>ll :OmniSharpBuildAsync <CR>
                "autocmd Filetype cs nmap <buffer> <leader>lv :SCCompileRunAF -pkg:dotnet <CR>
                "autocmd Filetype tex nmap <buffer> <leader>ll :SCCompileAF -shell-escape <CR>
                au Filetype tex setlocal sw=2
            " }
            "Bundle 'mhinz/vim-signify'
            " < Show added, deleted and modified lines > {
            " }
            " Bundle 'scrooloose/syntastic'
            " < Syntax checker > {
                "let g:syntastic_python_python_exe = 'python2'
                let g:syntastic_error_symbol='✗'
                let g:syntastic_warning_symbol='⚠'
                "let g:syntastic_cpp_compiler = 'clang++'
                let g:syntastic_cpp_compiler_options = ' -std=c++0x'
            " }
            Bundle 'Valloric/YouCompleteMe'
            " < Fast, fuzzy-search code completion engine > {
                let g:ycm_add_preview_to_completeopt = 1
                let g:ycm_autoclose_preview_window_after_completion = 1
                let g:ycm_global_ycm_extra_conf = '/home/abcdw/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py'
                let g:ycm_key_list_select_completion = []
                let g:ycm_key_list_previous_completion = []
                let g:ycm_collect_identifiers_from_tags_files = 1 " Let YCM read tags from Ctags file
                let g:ycm_use_ultisnips_completer = 1 " Default 1, just ensure
                let g:ycm_seed_identifiers_with_syntax = 1 " Completion for programming language's keyword
                let g:ycm_complete_in_comments = 1 " Completion in comments
                let g:ycm_complete_in_strings = 1 " Completion in string
                nnoremap <leader>g :YcmCompleter GoToDeclaration<CR>
            " }
            Bundle 'tpope/vim-markdown'
            " < Markdown mode > {
            " }
            " *** Syntax files *** {
                Bundle 'PotatoesMaster/i3-vim-syntax'
                Bundle 'python.vim'
                Bundle 'django.vim'
                Bundle 'OrangeT/vim-csharp.git'
                au BufNewFile,BufRead *.html       setlocal filetype=htmldjango sw=2
                au BufNewFile,BufRead admin.py     setlocal filetype=python.django
                au BufNewFile,BufRead urls.py      setlocal filetype=python.django
                au BufNewFile,BufRead models.py    setlocal filetype=python.django
                au BufNewFile,BufRead views.py     setlocal filetype=python.django
                au BufNewFile,BufRead settings.py  setlocal filetype=python.django
                au BufNewFile,BufRead forms.py     setlocal filetype=python.django
                au FileType html,xml,liquid set sw=2

            " }


            "Bundle 'marijnh/tern_for_vim'
            " < code-analysis engine for js > {
            " }
            "
            Bundle 'nosami/Omnisharp'
            " < Omnicompletion (intellisense) and more for C# > {
            " }
            Bundle "mattn/emmet-vim"
            " < High-speed HTML, XML, XSL coding and edition > {
                let g:user_emmet_leader_key = '<C-g>'
                let g:use_emmet_complete_tag = 1
            " }
            Bundle 'jmcantrell/vim-virtualenv'
            " < Vim python virtualenv manager > {
                let g:virtualenv_directory = '~/.virtualenvs'
            " }
            Bundle 'git://vim-latex.git.sourceforge.net/gitroot/vim-latex/vim-latex'
            " < Latex-suite > {
                set grepprg=grep\ -nH\ $*
                let g:tex_flavor='latex'
                let g:Tex_DefaultTargetFormat='pdf'
                let g:Tex_ViewRule_pdf='zathura'
                imap <C-g> <Plug>IMAP_JumpForward
                nmap <C-g> <Plug>IMAP_JumpForward
                function! Synctex()
                        " remove 'silent' for debugging
                        execute "silent !zathura --synctex-forward " . line('.') . ":" . col('.') . ":" . bufname('%') . " " . g:syncpdf
                endfunction
                map <C-enter> :call Synctex()<cr>
                " TODO: try dvi format
            " }

        " }
        " Appearance {
            " *** Colorschemes *** {
                Bundle 'xolox/vim-colorscheme-switcher'
                " <Cicrle through colorsechemes> {
                " }
                let g:colors_name="solarized"
                Bundle 'sjl/badwolf'
                Bundle 'w0ng/vim-hybrid'
                Bundle 'baskerville/bubblegum'
                Bundle 'hickop/vim-hickop-colors'
                Bundle 'altercation/vim-colors-solarized.git'
                Bundle 'cschlueter/vim-wombat'
                Bundle 'jnurmine/Zenburn'
                Bundle 'tomasr/molokai'
                Bundle 'chriskempson/base16-vim'
                Bundle 'HubbaBubbaFett/mustang'
                Bundle 'endel/vim-github-colorscheme'
                Bundle 'morhetz/gruvbox'
                " set term=xterm-256color
                " let g:solarized_termcolors=256
                " let g:solarized_visibility="low"
                " let g:base16colorspace=256
                " set t_Co=256
                set background=dark
                " colorscheme hybrid
                " colorscheme zenburn
                colorscheme solarized
                " colorscheme github
                " colorscheme mustang
                " colorscheme molokai
                set colorcolumn=80
                " echo g:colors_name
            " }
            Bundle 'bling/vim-airline'
            " < Pretty status line > {
                " let g:airline_theme='solarized'
                let g:airline_theme=g:colors_name

                let g:airline_powerline_fonts = 1
                let g:airline_enable_fugitive = 1
                " let g:airline#extensions#bufferline#enabled = 1
                let g:airline#extensions#tabline#enabled = 1
                let g:airline#extensions#eclim#enabled = 1
                let g:airline#extensions#branch#enabled = 1
                let g:airline#extensions#branch#empty_message = 'no scm'
                let g:airline#extensions#syntastic#enabled = 1
                " let g:airline#extensions#tagbar#enabled = 1
                let g:airline#extensions#tagbar#flags = 'f'

                let g:airline#extensions#virtualenv#enabled = 1
                let g:airline#extensions#hunks#enabled = 1
                let g:airline#extensions#hunks#hunk_symbols = ['+', '~', '-']
                let g:airline#extensions#ctrlp#color_template = 'normal'
                " let g:airline#extensions#ctrlp#show_adjacent_modes = 1
            " }
            "Bundle 'bling/vim-bufferline'
            " < Bufferline for airline integration > {
            " }
        " }

        " Bundle 'Yggdroot/indentLine'
        " < Such slow plugin >
        " Bundle 'nathanaelkane/vim-indent-guides.git'
        "{
            "let g:indent_guides_auto_colors = 1
            "let g:indent_guides_guide_size=1
            "let g:indent_guides_start_level=2
            "let g:indent_guides_enable_on_vim_startup=1
            ""hi IndentGuidesOdd  ctermbg=black
            ""hi IndentGuidesEven ctermbg=darkgrey
        " }


        "Bundle 'dbakker/vim-lint'
        Bundle 'gregsexton/gitv'
        " Bundle 'Lokaltog/vim-easymotion'
        " < EasyMotion >{
            " let g:EasyMotion_smartcase = 1
            " let g:EasyMotion_keys = 'JOEUTIDPYVWMFQKXBGLRH'
            " let g:EasyMotion_enter_jump_first = 1
            " let g:EasyMotion_space_jump_first = 1
            " let g:EasyMotion_prompt = '{n}>>> '
            " let g:EasyMotion_use_upper = 1
            " let g:EasyMotion_do_shade = 1
            " let g:EasyMotion_skipfoldedline = 0
            " let g:EasyMotion_startofline = 0
            " map <Leader> <Plug>(easymotion-prefix)
            " nmap <Leader>ss <Plug>(easymotion-s2)

            "vmap jj <Plug>(easymotion-j)
            "vmap kk <Plug>(easymotion-k)
            "nmap jj <Plug>(easymotion-j)
            "nmap kk <Plug>(easymotion-k)
            "nmap n <Plug>(easymotion-sn)
        " }
    "Bundle 'Mark'
    Bundle 't9md/vim-quickhl'
        " Bundle 'a.vim'
        Bundle 'vimwiki/vimwiki'
        " {
            "let g:vimwiki_ext2syntax = {}
            let g:vimwiki = {}
            let g:vimwiki.path = '~/yd/Documents/vimwiki'
            "let s:vimwiki.ext = '.md'
            "let s:vimwiki.syntax = 'markdown'
            "let s:vimwiki.diary_rel_path = 'journal/'
            "let s:vimwiki.diary_index = 'index'
            "let s:vimwiki.diary_header = 'Journal'
            "let s:vimwiki.diary_sort = 'asc'
            "let s:vimwiki.ext2syntax = {'.md': 'markdown'}
            let g:vimwiki_list = [g:vimwiki]
        " }


        "Bundle 'VimClojure'
        Bundle 'matrix.vim--Yang'
        Bundle 'tpope/vim-repeat'
        Bundle 'tpope/vim-fugitive.git'
        " < Git addon > {
            map <leader>gis :Gstatus<cr>
            map <leader>gia :Gcommit --amend<cr>
            map <leader>gid :Gdiff<cr>
        " }

        Bundle 'tpope/vim-surround'
        Bundle 'tpope/vim-dispatch'
        Bundle 'tpope/vim-abolish'
        " Bundle 'cwood/vim-django'
        " < Wrappers for django utils > {
            let g:django_projects = '~/work/repos/' "Sets all projects under project
            let g:django_activate_virtualenv = 1 "Try to activate the associated virtualenv
            let g:django_activate_nerdtree = 1 "Try to open nerdtree at the project root.
        " }

        Bundle 'klen/python-mode'
        " < Ultimate python plugin > {
            let g:pymode_lint_on_write = 0
            let g:pymode_folding = 0
            let g:pymode_rope = 0

        " }

        Bundle 'mjbrownie/vim-htmldjango_omnicomplete'


        Bundle 'sessionman.vim'
        " < Session manager plugin >{
            set viminfo='100,<500,s10,h,!
            "autocmd VimEnter * SessionList
            "autocmd VimEnter * if !argc() | SessionList | endif
        " }

        Bundle 'tpope/vim-fireplace'
        Bundle 'tpope/vim-classpath'
        Bundle 'guns/vim-clojure-static'
        Bundle 'bkad/CamelCaseMotion'
        " < CamelCaseMotion > {
            map <silent> w <Plug>CamelCaseMotion_w
            map <silent> b <Plug>CamelCaseMotion_b
            map <silent> e <Plug>CamelCaseMotion_e
            sunmap w
            sunmap b
            sunmap e
        " }

        "Bundle 'YankRing.vim'
        "Bundle 'mhinz/vim-startify'
        Bundle 'Shougo/neomru.vim'
        Bundle 'Shougo/unite.vim'
        " { < awesome Unite plugin >
	    let g:unite_prompt='>'
	    let g:unite_split_rule='botright'
	    map <C-p> :Unite -start-insert buffer file_mru file/async file_rec/async<CR>
            autocmd FileType unite call s:unite_settings()
            function! s:unite_settings()
                " Play nice with supertab
                " let b:SuperTabDisabled=1
                " Enable navigation with control-j and control-k in insert mode
                imap <buffer> <C-j>   <Plug>(unite_select_next_line)
                imap <buffer> <C-k> <Plug>(unite_select_previous_line)
            endfunction
        " }
        Bundle 'tsukkee/unite-help'

        " Tmux plugins {
            Bundle 'edkolev/tmuxline.vim'
            " <Generate statusline for tmux> {
            " }
            Bundle 'benmills/vimux'
            " <Plugin for interact with tmux> {
                let VimuxUseNearest = 1
                function! VimuxSlime(visual)
                    let @v=substitute(@v,'\(.*\)\n\%$','\1','g')
                    " remove last \n in register
                    if a:visual == 0
                        let @v = ""
                    endif
                    if @v == ""
                    let @v = getline(".")
                    endif

                    call VimuxSendText(@v)
                    call VimuxSendKeys("Enter")
                endfunction

                nmap <Leader>vr :call VimuxRunCommand("")<CR>
                nmap <Leader>vv :call VimuxRunLastCommand()<CR>
                vmap <Leader>e "vy:call VimuxSlime(1)<CR>
                nmap <Leader>e :call VimuxSlime(0)<CR>
            " }
            Bundle 'christoomey/vim-tmux-navigator'
            Bundle 'wellle/tmux-complete.vim'
            " <completion from tmux> {
                let g:tmuxcomplete#trigger = 'omnifunc'
                " :Unite tmuxcomplete/lines
            " }
            Bundle 'tmux-plugins/vim-tmux'
            " <Syntax highlight and help> {
            " }
        " }

        Bundle 'parkr/vim-jekyll'
        Bundle 'elzr/vim-json'
        Bundle 'rking/ag.vim'
        " Bundle 'diffchar.vim'
        Bundle 'stefandtw/quickfix-reflector.vim'
        Bundle 'tpope/vim-rsi'
        " <Readline style insertions (c-a, c-e, ...) > {
        " }


        Bundle 'eiffelhub/vim-eiffel'
        " <Syntax highlight and indent> {
        " }

        Bundle 'dbext.vim'
        " <SQL db extension> {
            let g:dbext_default_profile_usual='type=PGSQL:user=postgres'
        " }
        " Bundle 'SQLComplete.vim'

        filetype indent on
        filetype plugin on

        autocmd FileType * set formatoptions-=o
    " }
endif
" }

set secure
