" VIM Configuration - Geoffrey FROGEYE
"

set nocompatible
filetype off

""" PLUGINS MANAGEMENT  """
" Voir :h vundle

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'

Plugin 'L9'
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
Plugin 'tomasr/molokai'
"Bundle 'Shougo/neosnippet'
"Bundle 'Shougo/neosnippet-snippets'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-repeat'
Plugin 'tpope/tpope-vim-abolish'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'airblade/vim-gitgutter'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'mbbill/undotree'
Plugin 'xolox/vim-misc'
Plugin 'xolox/vim-easytags'
Plugin 'majutsushi/tagbar'
Plugin 'wellle/targets.vim'
Plugin 'Chiel92/vim-autoformat'
" Plugin 'Valloric/YouCompleteMe'
Plugin 'artur-shaik/vim-javacomplete2'
Plugin 'tomtom/tcomment_vim'
Plugin 'Shougo/denite.nvim'
Plugin 'tomlion/vim-solidity'
Plugin 'godlygeek/tabular'

call vundle#end()            " required
filetype plugin indent on    " required

""" UNDOTREE """

nmap <F7> :UndotreeToggle<CR>:UndotreeFocus<CR>

""" CTRLP """

let g:ctrlp_custom_ignore = {
    \ 'dir':  '\v([\/]\.(git|hg|svn)|log|node_modules|bower_components|__pycache__|vendor|output|buildroot|doc)$',
    \ 'file': '\v\.(exe|so|dll|o|pyc)$',
    \ 'link': 'SOME_BAD_SYMBOLIC_LINKS',
    \ }

let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlPMixed'
map <a-p> :CtrlPMRUFiles<CR>

""" TAGBAR """

nmap <F8> :TagbarToggle<CR>

""" VIM-AIRLINE """

set noshowmode
set laststatus=2
let g:airline_powerline_fonts = 1
" let g:airline#extensions#syntastic#enabled = 1
let g:airline#extensions#tabline#enabled = 1

let g:airline_section_a = airline#section#create(['mode'])
let g:airline_section_b = airline#section#create(['branch', 'hunks'])
let g:airline_section_z = airline#section#create(['%B', '@', '%l', ':', '%c'])
let g:airline_theme = 'wombat'

""" YOUCOMPLETEME """

" let g:ycm_global_ycm_extra_conf = '~/.config/ycm_extra_conf.py'
let g:ycm_global_ycm_extra_conf = '/usr/share/vim/vimfiles/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
let g:ycm_server_python_interpreter = '/usr/bin/python2'

nmap gTi :YcmCompleter GoToInclude<CR>
nmap gTc :YcmCompleter GoToDeclaration<CR>
nmap gTf :YcmCompleter GoToDefinition<CR>
nmap gt :YcmCompleter GoTo<CR>
nmap gT :YcmCompleter GoToImprecise<CR>
nmap gTr :YcmCompleter GoToReference<CR>

""" AUTOFORMAT """
nmap <F3> :Autoformat<CR>

""" JAVACOMPLETE """

autocmd FileType java setlocal omnifunc=javacomplete#Complete

""" VIM SETTINGS """

set encoding=utf-8
set title

set number
set ruler
set wrap

set scrolloff=5

set ignorecase
set smartcase

set incsearch

set hlsearch

set tabstop=4
set shiftwidth=4
set expandtab

set visualbell
set noerrorbells

set backspace=indent,eol,start

set hidden
set updatetime=250

set cursorcolumn

syntax enable

set background=dark
colorscheme molokai
let g:molokai_original = 1

" From http://stackoverflow.com/a/5004785/2766106
set list
set listchars=tab:╾╌,trail:·,extends:↦,precedes:↤,nbsp:_
set showbreak=↪

filetype on
filetype plugin on
filetype indent on

" Put plugins and dictionaries in this dir (also on Windows)
let vimDir = '$HOME/.vim'
let &runtimepath.=','.vimDir

" Keep undo history across sessions by storing it in a file
if has('persistent_undo')
    let myUndoDir = expand(vimDir . '/undodir')
    " Create dirs
    call system('mkdir ' . vimDir)
    call system('mkdir ' . myUndoDir)
    let &undodir = myUndoDir
    set undofile
endif

" Allow saving of files as sudo when I forgot to start vim using sudo.
" From https://stackoverflow.com/a/7078429
cmap w!! w !sudo tee > /dev/null %

imap jk <Esc>
imap mù <Esc>
map <Enter> o<Esc>
nmap <C-H> :bp<CR>
nmap <C-L> :bn<CR>
nmap <C-K> kkkkkkkkkkkkkkkkkkkkk
nmap <C-J> jjjjjjjjjjjjjjjjjjjjj