3 " Author:   Samir Benmendil <samir.benmendil[at]gmail[dot]com>
 
   7 set runtimepath ^=$XDG_CONFIG_HOME/vim
 
   8 set runtimepath +=$XDG_CONFIG_HOME/vim/after
 
  11 " remove all autocommands
 
  14 call plug#begin('$XDG_DATA_HOME/vim')
 
  15 " This does not update vim-plug, use PlugUpgrade instead
 
  16 Plug 'junegunn/vim-plug'
 
  18 Plug 'airblade/vim-gitgutter'
 
  19 Plug 'alepez/vim-gtest'
 
  20 Plug 'andrewradev/switch.vim'
 
  21 Plug 'bling/vim-airline'
 
  22 Plug 'chrisbra/checkattach'
 
  23 Plug 'derekwyatt/vim-fswitch'
 
  25 Plug 'firef0x/pkgbuild.vim'
 
  26 Plug 'junegunn/vim-easy-align'
 
  27 Plug 'justinmk/vim-sneak'
 
  28 Plug 'klen/python-mode'
 
  29 Plug 'kshenoy/vim-signature'
 
  30 Plug 'majutsushi/tagbar'
 
  31 Plug 'octol/vim-cpp-enhanced-highlight'
 
  32 Plug 'raimondi/delimitmate'
 
  33 Plug 'ram-z/vim-clang-format', { 'branch': 'fix_undo' }
 
  34 Plug 'ram-z/vimwiki', { 'branch': 'no_override_map' }
 
  35 Plug 'scrooloose/syntastic'
 
  36 Plug 'sgeb/vim-diff-fold'
 
  37 Plug 'shougo/unite.vim'
 
  38 Plug 'shougo/vimproc.vim'
 
  40 Plug 'thinca/vim-qfreplace'
 
  41 Plug 'tomtom/tcomment_vim'
 
  42 Plug 'tpope/vim-abolish'
 
  43 Plug 'tpope/vim-endwise'
 
  44 Plug 'tpope/vim-eunuch'
 
  45 Plug 'tpope/vim-fugitive'
 
  46 Plug 'tpope/vim-repeat'
 
  47 Plug 'tpope/vim-surround'  "investigate vim-sandwich
 
  48 Plug 'tpope/vim-unimpaired'
 
  49 Plug 'tweekmonster/spellrotate.vim'
 
  50 Plug 'valloric/youcompleteme', { 'do': './install.py --clang-completer' }
 
  51 Plug 'vim-scripts/mediawiki.vim'
 
  52 Plug 'vim-scripts/replacewithregister'
 
  53 Plug 'vim-scripts/yankring.vim'
 
  56 Plug 'flazz/vim-colorschemes'
 
  59 Plug 'sirver/ultisnips'
 
  60 Plug 'honza/vim-snippets'
 
  63 Plug 'kana/vim-textobj-user'
 
  64 Plug 'julian/vim-textobj-variable-segment'
 
  65 Plug 'sgur/vim-textobj-parameter'
 
  66 Plug 'kana/vim-operator-user'
 
  69 " find an alternative (latex-box? Automatic Latex Plugin?)
 
  70 Plug 'vim-latex/vim-latex'
 
  72 " needs editing colorscheme
 
  73 " Plug 'jeaye/color_coded'
 
  74 " Check LucHermites plugins: https://github.com/LucHermitte/lh-cpp
 
  79 filetype plugin indent on
 
  84 let g:gruvbox_contrast_dark  = 'hard'
 
  85 let g:gruvbox_contrast_light = 'soft'
 
  89 " moving around, searching and patterns {{{2
 
  90 set incsearch           " show match for partly typed search command
 
  91 set ignorecase          " ignore case when using a search pattern
 
  92 set smartcase           " override 'ignorecase' when pattern has upper case characters
 
  93 set hlsearch            " highlight all matches for the last used search pattern
 
  95 set nostartofline       " don't move the cursor to the first non-blank char of a line
 
  99 set path+=/usr/include/c++/*
 
 101 " displaying text {{{2
 
 102 set nowrap                      " long lines wrap
 
 103 set linebreak                   " wrap long lines at a character in 'breakat'
 
 104 set showbreak=↪                 " show these chars for wrapped lines
 
 105 set breakindent                 " preserve indentation in wrapped text
 
 107 set lazyredraw                  " don't redraw while executing macros
 
 109 set list                        " show chars defined in 'listchars'
 
 110 set listchars=tab:❭\            " list of strings used for list mode
 
 111 set listchars+=extends:❯,precedes:❮
 
 112 " Only shown when not in insert mode
 
 113 au InsertLeave * :set listchars+=trail:·
 
 116     au InsertEnter * :set listchars-=trail:·
 
 117     au InsertLeave * :set listchars+=trail:·
 
 120 set scrolloff=5                 " number of screen lines to show around the cursor
 
 121 set sidescroll=1                " number of collumns to scroll
 
 122 set sidescrolloff=1             " don't scroll over the listchars
 
 124 set fillchars=diff:⣿,vert:│
 
 126 set nonumber                    " show the line number for each line
 
 127 set norelativenumber            " show the relative line number for each line
 
 129 " syntax, highlighting and spelling {{{2
 
 130 set synmaxcol=800               " don't highlight long lines
 
 132 set dictionary=spell            " list of dictionary files for keyword completion
 
 136 " multiple windows {{{2
 
 137 set laststatus=2                " 0, 1 or 2; when to use a status line for the last window
 
 139 set previewheight=20            " default height for the preview window
 
 143 " set splitbelow                  " a new window is put below of the current one
 
 144 set splitright                  " a new window is put right of the current one
 
 149 " using the mouse {{{2
 
 150 set mouse=rnv                   " list of flags for using the mouse
 
 151 set ttymouse=xterm              " type of mouse
 
 153 " messages and info {{{2
 
 154 set showcmd         " Show (partial) command in status line.
 
 155 set ruler           " show the cursor position all the time
 
 156 set confirm         " Ask what to do when closing unsaved documents
 
 157 set shortmess=      " reset option
 
 158 set shortmess+=a    " all abbreviations
 
 159 set shortmess+=o    " overwrite file-written message
 
 160 set shortmess+=O    " file-read message overrides previous
 
 161 set shortmess+=t    " truncate file message at start
 
 162 set shortmess+=T    " truncate other messages in the middle
 
 163 set shortmess+=W    " don't give 'written' or '[w]' when writing a file
 
 164 set shortmess+=A    " ignore swapfile warning
 
 165 set shortmess+=I    " no splash screen
 
 168 set backspace=indent,eol,start  " allow backspacing over everything in insert mode
 
 170 set showmatch                   " Show matching brackets.
 
 172 set nojoinspaces                " don't use two spaces after '.' when joining a line
 
 173 set formatoptions+=j    " Delete comment leader when joining lines
 
 174 set formatoptions+=c    " Autowrap comments using textwidth
 
 175 set formatoptions+=r    " Insert comment leader after hitting <Enter>
 
 176 set formatoptions+=n    " Recognize numbered lists
 
 177 set formatoptions+=q    " Allow formatting of comments with "gq".
 
 178 set formatoptions+=l    " do not wrap lines that have been longer when starting insert mode already
 
 179 set formatoptions+=t    " Auto-wrap text using textwidth
 
 180 set formatoptions-=o    " Do not insert comment leader after hitting o or O in normal mode
 
 182 set nrformats=hex               " number formats recognized for CTRL-A and CTRL-X commands
 
 184 set complete=.       " scan the current buffer ( 'wrapscan' is ignored)
 
 185 set complete+=w      " scan buffers from other windows
 
 186 set complete+=b      " scan other loaded buffers that are in the buffer list
 
 187 set complete+=u      " scan the unloaded buffers that are in the buffer list
 
 188 set complete+=t      " scan tags
 
 189 set complete+=i      " scan current and included files
 
 190 set complete+=kspell " use the currently active spell checking |spell|
 
 192 " whether to use a popup menu for Insert mode completion
 
 193 set completeopt=longest,menuone,preview
 
 195 " tabs and indent {{{2
 
 196 set shiftwidth=4                " number of spaces used for each step of (auto)indent
 
 197 set smarttab                    " a <Tab> in an indent inserts 'shiftwidth' spaces
 
 198 set softtabstop=4               " if non-zero, number of spaces to insert for a <Tab>
 
 199 set shiftround                  " round to 'shiftwidth' for "<<" and ">>"
 
 200 set expandtab                   " expand <Tab> to spaces in Insert mode
 
 203 set pastetoggle=<F11>           " key sequence to toggle paste mode
 
 206 set foldmethod=marker           " folding type
 
 207 set foldlevelstart=0            " value for 'foldlevel' when starting to edit a file
 
 209 " open folds when jumping to line
 
 212 set viewoptions=cursor          " save cursor position
 
 213 set viewoptions+=folds          " save folds
 
 216 set diffopt+=filler         " show filler lines
 
 217 set diffopt+=vertical       " always vertical split
 
 218 set diffopt+=context:10     " 10 lines context between changes
 
 220 " reading and writing files {{{2
 
 221 set modeline                    " read modelines
 
 222 set modelines=2                 " only check first/last 2 lines
 
 224 set writebackup                 " write a backup file before overwriting a file
 
 225 set backup                      " keep a backup after owerwriting a file
 
 226 set backupdir=$XDG_CACHE_HOME/vim/backup//
 
 228 set backupskip+=.netrc          " skip netrc
 
 229 set backupskip+=/dev/shm/pass*  " skip passwordstore files
 
 231 set undofile                    " persistent undo history
 
 232 set undodir=$XDG_CACHE_HOME/vim/undo//
 
 236     au BufWritePre .netrc         setlocal noundofile
 
 237     au BufWritePre /dev/shm/pass* setlocal noundofile
 
 238     au BufWritePre /tmp/*         setlocal noundofile
 
 241 set autowrite                   " automatically write a file when leaving a modified buffer
 
 242 set autoread                    " automatically read a file that has been modified
 
 246 set directory=$XDG_CACHE_HOME/vim/swap//
 
 248 " command line editing {{{2
 
 249 set history=5000                " how many command lines are remembered
 
 250 set wildmenu                    " command-line completion shows a list of matches
 
 251 set wildmode=longest:full,full  " specifies how command line completion works
 
 252 set wildignorecase              " ignore case when completing file names
 
 254 set wildignore+=.hg,.git,.svn                    " Version control
 
 255 set wildignore+=*.aux,*.out,*.toc                " LaTeX intermediate files
 
 256 set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg   " binary images
 
 257 set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
 
 258 set wildignore+=*.spl                            " compiled spelling word lists
 
 259 set wildignore+=*.sw?                            " Vim swap files
 
 260 set wildignore+=*.luac                           " Lua byte code
 
 261 set wildignore+=*.pyc                            " Python byte code
 
 262 set wildignore+=*.orig                           " Merge resolution files
 
 264 " running make and jumping to errors {{{2
 
 265 set makeprg=make\ -w     " print changing directories
 
 267 set grepprg=ag\ --vimgrep\ $*
 
 269 " language specific {{{2
 
 270 set isfname-==    " don't treat `=` as being part of filenames
 
 273 set virtualedit+=block     " let cursor move past last char in <C-V> mode
 
 274 set virtualedit+=onemore   " allow the cursor to move just past the end of the line
 
 275 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
 
 277 set viewdir=$XDG_CACHE_HOME/vim/view//
 
 279 set sessionoptions+=unix,slash  " damn windows and it's silly ways
 
 282 " Resize splits when the window is resized {{{2
 
 285     autocmd VimResized * :wincmd =
 
 288 " Only show cursorline in the current window and in normal mode {{{2
 
 291     au WinLeave,InsertEnter * set nocursorline
 
 292     au WinEnter,InsertLeave * set cursorline
 
 295 " Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
 
 298     au StdinReadPost * :set buftype=nofile
 
 301 " Jump to last known cursor position {{{2
 
 304     " blacklist certain filetype
 
 305     let blacklist = ['gitcommit']
 
 306     autocmd BufReadPost *
 
 307                 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
 
 308                 \   exe "normal! g`\"" |
 
 312 " Check for file modifications automatically {{{2
 
 313 " (current buffer only)
 
 314 " Use :NoAutoChecktime to disable it (uses b:autochecktime)
 
 315 fun! MyAutoCheckTime()
 
 316   " only check timestamp for normal files
 
 317   if &buftype != '' | return | endif
 
 318   if ! exists('b:autochecktime') || b:autochecktime
 
 320     let b:autochecktime = 1
 
 323 augroup MyAutoChecktime
 
 325   au FocusGained,BufEnter,CursorHold,InsertEnter * call MyAutoCheckTime()
 
 327 command! NoAutoChecktime let b:autochecktime=0
 
 328 command! ToggleAutoChecktime let b:autochecktime=!get(b:, 'autochecktime', 0) | echom "b:autochecktime:" b:autochecktime
 
 332   au TerminalOpen * if &buftype == 'terminal' | setlocal bufhidden=hide | endif
 
 337 " allow both <space> and \ to be <leader>
 
 341 nnoremap <leader>r :make!<cr>
 
 342 nnoremap <leader><cr> :make!<cr>
 
 345 nnoremap <silent> <Leader>/ :silent nohl<CR>
 
 348 nnoremap <leader>[ :tabprev<cr>
 
 349 nnoremap <leader>] :tabnext<cr>
 
 351 " paste from selection
 
 352 nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
 
 353 " paste from clipboard
 
 354 nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
 
 356 " strip trailing whitespace
 
 357 function! StripWhitespace(line1, line2, ...)  " {{{2
 
 358   let s_report = &report
 
 360   let pattern = a:0 ? a:1 : '\s\+$'
 
 361   let oldview = winsaveview()
 
 362   exe 'keepjumps keeppatterns '.a:line1.','.a:line2.'substitute/'.pattern.'//e'
 
 363   if oldview != winsaveview()
 
 366   call winrestview(oldview)
 
 367   let &report = s_report
 
 369 command! -range=% -nargs=0 -bar Untrail keepjumps call StripWhitespace(<line1>,<line2>)
 
 370 nnoremap <silent> <leader>ww :Untrail<CR>
 
 373 vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
 
 374 nnoremap <leader>S ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
 
 376 " jump to last cursor position
 
 379 " Select (charwise) the contents of the current line, excluding indentation.
 
 383 nnoremap U :syntax sync fromstart<cr>:AirlineRefresh<cr>:redraw!<cr>
 
 386 " nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
 
 387 " nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
 
 394 " display the number of matches for the last search
 
 395 nmap <Leader># :%s:<C-R>/::gn<CR>
 
 397 " center cursor after search and open folds
 
 401 " same when jumping around
 
 404 nnoremap <c-o> <c-o>zzzv
 
 405 nnoremap <c-i> <c-i>zzzv
 
 407 " Not using the default mappings of 'To line from top/bottom'
 
 413 " Heresy, emacs insert bindings
 
 414 inoremap <C-A> <Esc>I
 
 415 inoremap <C-E> <Esc>A
 
 416 cnoremap <C-A> <Home>
 
 419 " proper movement when lines are wrapped
 
 420 noremap <expr> j (v:count == 0 ? 'gj' : 'j')
 
 421 noremap <expr> k (v:count == 0 ? 'gk' : 'k')
 
 427 noremap  <Right> <NOP>
 
 429 inoremap <Down>  <NOP>
 
 430 inoremap <Left>  <NOP>
 
 431 inoremap <Right> <NOP>
 
 433 cnoremap <Down>  <NOP>
 
 434 cnoremap <Left>  <NOP>
 
 435 cnoremap <Right> <NOP>
 
 437 cnoremap <C-J>   <Down>
 
 438 cnoremap <C-H>   <Left>
 
 439 cnoremap <C-L>   <Right>
 
 441 " close all folds open fold in cursor
 
 444 map <F1> :ls<CR>:b<space>
 
 446 " move between windows (skip previewwindow)
 
 447 nnoremap <silent> <C-L> <C-W>w<C-W>:if &previewwindow \| wincmd w \| endif<CR>
 
 448 nnoremap <silent> <C-H> <C-W>W<C-W>:if &previewwindow \| wincmd W \| endif<CR>
 
 449 tnoremap <silent> <C-L> <C-W>w<C-W>:if &previewwindow \| wincmd w \| endif<CR>
 
 450 tnoremap <silent> <C-H> <C-W>W<C-W>:if &previewwindow \| wincmd W \| endif<CR>
 
 452 "xterm mouse with middleclick paste
 
 453 nnoremap <MiddleMouse> i<MiddleMouse>
 
 454 vnoremap <MiddleMouse> s<MiddleMouse>
 
 456 " fix legacy vi inconsistency
 
 461 " allow repeat operator on visual
 
 462 vnoremap . :normal .<CR>
 
 464 " add line without changing position or leaving mode
 
 465 noremap <silent> <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
 
 466 noremap <silent> <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
 
 468 " Don't use Ex mode, use Q for formatting
 
 471 " break undo sequence before removing word
 
 472 inoremap <C-W> <C-G>u<C-W>
 
 474 nnoremap coe :set <C-R>=&expandtab ? 'noexpandtab' : 'expandtab'<CR><CR>
 
 475 nnoremap [oe :set expandtab<CR>
 
 476 nnoremap ]oe :set noexpandtab<CR>
 
 478 for idt in range(1,8)
 
 479   exe 'nnoremap co'.idt.' :setlocal tabstop='.idt.' shiftwidth='.idt.' softtabstop='.idt.'<CR>'
 
 482 " toggle auto format of text
 
 483 nnoremap coa :set <C-R>=&formatoptions =~ "a" ? 'formatoptions-=a' : 'formatoptions+=a'<CR><CR>
 
 484 nnoremap [oa :set formatoptions+=a<CR>
 
 485 nnoremap ]oa :set formatoptions-=a<CR>
 
 487 " space will toggle current fold in normal mode
 
 488 nnoremap <leader><Space> za
 
 489 " create folds around visual selection
 
 490 vnoremap <leader><Space> zf
 
 493 cabbrev w!! SudoWrite
 
 495 " uppercase previous word
 
 496 inoremap <C-C> <Esc>gUiwgi
 
 498 " http://git.io/v3ZeU
 
 499 nmap <silent> <leader>qq :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
 
 501 " plugins options {{{1
 
 503 let g:airline#extensions#whitespace#enabled = 1
 
 504 let g:airline#extensions#tabline#enabled = 1
 
 505 let g:airline_powerline_fonts = 1
 
 508 let g:checkattach_filebrowser = 'ranger'
 
 509 let g:checkattach_once = 'y'
 
 512 let delimitMate_expand_cr = 2
 
 513 let g:delimitMate_expand_space = 1
 
 516 nnoremap <silent> <Leader>ff :FSHere<CR>
 
 517 nnoremap <silent> <Leader>fl :FSRight<CR>
 
 518 nnoremap <silent> <Leader>fh :FSLeft<CR>
 
 519 nnoremap <silent> <Leader>fj :FSBelow<CR>
 
 520 nnoremap <silent> <Leader>fk :FSAbove<CR>
 
 521 nnoremap <silent> <Leader>fL :FSSplitRight<CR>
 
 522 nnoremap <silent> <Leader>fH :FSSplitLeft<CR>
 
 523 nnoremap <silent> <Leader>fJ :FSSplitBelow<CR>
 
 524 nnoremap <silent> <Leader>fK :FSSplitAbove<CR>
 
 527 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
 
 528 " delete fugitive buffers when closed
 
 529 autocmd BufReadPost fugitive://* set bufhidden=delete
 
 531 nnoremap <silent> <leader>gs :Gstatus<CR>
 
 532 nnoremap <silent> <leader>gd :Gdiff<CR>
 
 533 nnoremap <silent> <leader>gc :Gcommit -v<CR>
 
 534 nnoremap <silent> <leader>ga :Gwrite<cr>
 
 535 nnoremap <silent> <leader>gb :Gblame<cr>
 
 538 nnoremap <F7> :GundoToggle<CR>
 
 541 let g:indent_guides_default_mapping = 0
 
 542 let g:indent_guides_guide_size = 1
 
 543 nmap <silent> cog <Plug>IndentGuidesToggle
 
 544 nmap <silent> [og <Plug>IndentGuidesEnable
 
 545 nmap <silent> ]og <Plug>IndentGuidesDisable
 
 547 " close-another-window {{{2
 
 548 nnoremap <silent> <C-W>c  <NOP>
 
 549 nnoremap <silent> <C-W>cc <C-W>c
 
 550 nnoremap <silent> <C-W>ch :CloseLeftWindow<CR>
 
 551 nnoremap <silent> <C-W>cl :CloseRightWindow<CR>
 
 552 nnoremap <silent> <C-W>cj :CloseBelowWindow<CR>
 
 553 nnoremap <silent> <C-W>ck :CloseAboveWindow<CR>
 
 557 let g:pymode_rope_completion = 0
 
 558 let g:pymode_rope = 0
 
 560 let g:pymode_folding = 1
 
 561 let g:pymode_lint_ignore = "E221,E266,E501"
 
 562 let g:pymode_lint_cwindow = 0           " don't open cwindow when linting
 
 563 let g:pymode_syntax_space_errors = 0    " don't bother me when I'm typing
 
 566 " disable '[ mappings
 
 568 let g:SignatureMap = {
 
 569   \ 'GotoNextLineAlpha'  :  "",
 
 570   \ 'GotoPrevLineAlpha'  :  "",
 
 571   \ 'GotoNextSpotAlpha'  :  "",
 
 572   \ 'GotoPrevSpotAlpha'  :  "",
 
 576 let g:switch_mapping = "<Leader>s"
 
 579 nmap <silent> z] <Plug>(SpellRotateForward)
 
 580 nmap <silent> z[ <Plug>(SpellRotateBackward)
 
 581 vmap <silent> z] <Plug>(SpellRotateForwardV)
 
 582 vmap <silent> z[ <Plug>(SpellRotateBackwardV)
 
 585 let g:syntastic_enable_highlighting = 0
 
 586 let g:syntastic_error_symbol='E'
 
 587 let g:syntastic_style_error_symbol='S'
 
 588 let g:syntastic_warning_symbol='W'
 
 589 let g:syntastic_style_warning_symbol='S'
 
 590 let g:syntastic_always_populate_loc_list=1
 
 591 nmap <silent> <leader>y :SyntasticCheck<cr>
 
 594   let g:syntastic_check_on_open=1
 
 598 map <F5> :TagbarToggle<cr>
 
 599 let g:tagbar_sort = 0
 
 600 let g:tagbar_compact = 1
 
 601 let g:tagbar_autoshowtag = 1
 
 602 let g:tagbar_width = 25
 
 603 let g:tagbar_iconchars = ['+', '-']
 
 606 let g:tcomment_textobject_inlinecomment = 'gic'
 
 607 let g:tcomment#filetype#guess = 0
 
 610 let g:UltiSnipsEditSplit = 'vertical'
 
 611 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
 
 613   let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
 
 615 let g:UltiSnipsExpandTrigger       = "<tab>"
 
 616 let g:UltiSnipsJumpForwardTrigger  = "<tab>"
 
 617 let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
 
 619 " UltiSnips completion function that tries to expand a snippet. If there's no
 
 620 " snippet for expanding, it checks for completion window and if it's shown,
 
 621 " selects first element. If there's no completion window it tries to jump to
 
 622 " next placeholder. If there's no placeholder it just returns TAB key
 
 623 " https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-15451411
 
 624 function! g:UltiSnips_Complete()
 
 625     call UltiSnips#ExpandSnippet()
 
 626     if g:ulti_expand_res == 0
 
 630             call UltiSnips#JumpForwards()
 
 631             if g:ulti_jump_forwards_res == 0
 
 638 au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
 
 639 let g:UltiSnipsListSnippets="<c-e>"
 
 642 call unite#filters#matcher_default#use(['matcher_fuzzy'])
 
 643 call unite#custom#profile('default', 'context', {
 
 645             \ 'direction': 'botright'
 
 648 nnoremap [unite] <Nop>
 
 649 nmap <leader>u [unite]
 
 650 nnoremap [unite]u :UniteResume<CR>
 
 651 nnoremap <silent> [u :UnitePrevious<CR>
 
 652 nnoremap <silent> ]u :UniteNext<CR>
 
 655 " seems not respected
 
 656 let g:unite_source_grep_max_candidates = 2000
 
 658     " Use ag in unite grep source.
 
 659     let g:unite_source_grep_command = 'ag'
 
 660     let g:unite_source_grep_default_opts = '--smart-case --vimgrep --ignore ''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'''
 
 661     let g:unite_source_grep_recursive_opt = ''
 
 663 nnoremap <silent> [unite]a :<C-u>Unite grep:.::
\12\17<CR>
 
 664 nnoremap <silent> [unite]A :<C-u>Unite grep:.:-w:
\12\17<CR>
 
 665 command! -nargs=1 Ag Unite grep:.::<args>
 
 667 " unite-file_rec {{{3
 
 669     " Use ag in unite rec source
 
 670     let g:unite_source_rec_async_command = ['ag', '--follow', '--nocolor', '--nogroup', '-g', '']
 
 672 nnoremap <silent> [unite]f :<C-u>Unite -start-insert file_rec/async<CR>
 
 673 call unite#custom#source('file_rec/async', 'sorters', 'sorter_selecta')
 
 676 call unite#custom#default_action('buffer', 'open')
 
 677 nnoremap <silent> [unite]b :<C-u>Unite buffer:-<CR>
 
 680 let g:unite_source_menu_menus = {}
 
 681 let g:unite_source_menu_menus.fugitive = { 'description' : 'fugitive menu'}
 
 682 let g:unite_source_menu_menus.fugitive.command_candidates = {
 
 683             \ 'Gstatus <Leader>gs' : 'Gstatus',
 
 684             \ 'Gcommit -v <Leader>gc' : 'Gcommit -v',
 
 688 nnoremap <silent> <leader>gg :<C-u>Unite menu:fugitive<CR>
 
 690 let g:unite_source_history_yank_enable = 1
 
 691 nnoremap <silent> [unite]p :<C-u>Unite history/yank<CR>
 
 694 nnoremap <silent> <leader>p :YRShow<cr>
 
 695 let g:yankring_history_dir = expand('$XDG_CACHE_HOME/vim')
 
 696 let g:yankring_replace_n_pkey = ''
 
 697 let g:yankring_replace_n_nkey = ''
 
 699 " map Y to y$ for the yank ring
 
 700 function! YRRunAfterMaps()
 
 701     nnoremap Y   :<C-U>YRYankCount 'y$'<CR>
 
 705 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
 
 706 let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
 
 707 let g:ycm_extra_conf_vim_data = ['getcwd()']
 
 708 let g:ycm_add_preview_to_completeopt = 1
 
 709 let g:ycm_complete_in_comments = 1
 
 710 let g:ycm_complete_in_strings  = 1
 
 711 let g:ycm_autoclose_preview_window_after_insertion = 0
 
 713 " vim-easy-align {{{2
 
 714 " start interactive EasyAlign in visual mode
 
 715 vmap <Enter> <Plug>(EasyAlign)
 
 716 nmap ga <Plug>(EasyAlign)
 
 719 let g:gtest#highlight_failing_tests = 0
 
 721 nnoremap <Leader>tt :GTestRun<CR>
 
 722 nnoremap <Leader>ta :GTestCase *<CR>:GTestName *<CR>:GTestRun<CR>
 
 723 nnoremap <Leader>tu :GTestRunUnderCursor<CR>
 
 726 let g:vim_json_syntax_conceal = 0
 
 729 let g:tex_flavor='latex'
 
 730 let g:Tex_DefaultTargetFormat='pdf'
 
 731 let g:Tex_MultipleCompileFormats='pdf'
 
 734 let g:sneak#streak = 1
 
 735 let g:sneak#target_labels = "aoeuisnthdpylrcgfqjkxzmwvz" " dvorak
 
 736 let g:sneak#use_ic_scs = 1  " follow 'ignorecase' and 'smartcase'
 
 753 let g:vimwiki_list = [{'path': '$XDG_DATA_HOME/vimwiki'}]
 
 754 let g:vimwiki_auto_chdir = 1
 
 756   au! BufRead            $XDG_DATA_HOME/vimwiki/index.wiki   !git -C "%:p:h" pull -q
 
 757   au! BufRead,BufNewFile $XDG_DATA_HOME/vimwiki/diary/*.wiki !git -C "%:p:h" pull -q
 
 758   au! BufWritePost       $XDG_DATA_HOME/vimwiki/*.wiki       exe '!git add "<afile>";git commit -qm"' . strftime("%FT%R") . '";git push -q'
 
 763 " Convenient command to see the difference between the current buffer and the
 
 764 " file it was loaded from, thus the changes you made.
 
 765 " Only define it when not defined already.
 
 766 if !exists(":DiffOrig")
 
 767   command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
 
 768                   \ | wincmd p | diffthis
 
 772 function! SortLinesOpFunc(...)
 
 775 nnoremap <silent> gs :<C-U>set operatorfunc=SortLinesOpFunc<CR>g@
 
 776 vnoremap <silent> gs :sort<cr>
 
 779 function! EditConfig(what)
 
 780     let l:dir = split(&runtimepath,',')[0]
 
 782         let l:file = expand($MYVIMRC)
 
 783     elseif ! isdirectory(globpath(l:dir, a:what))
 
 784         echoe a:what." is not valid!"
 
 785     elseif empty(&filetype)
 
 786         echoe 'filetype is empty!'
 
 788         let l:file = l:dir.'/'.a:what.'/'.&filetype.'.vim'
 
 791     execute ':vsplit '.file
 
 794 nmap <leader>ev :call EditConfig('vimrc')<CR>
 
 795 nmap <leader>ef :call EditConfig('ftplugin')<CR>
 
 796 nmap <leader>es :call EditConfig('syntax')<CR>
 
 797 nmap <leader>ei :call EditConfig('indent')<CR>
 
 798 nmap <leader>eu :UltiSnipsEdit<CR>:lcd %:p:h<CR>
 
 801 " http://tex.stackexchange.com/a/52932
 
 802 let g:myLangList=["en_gb","en_us","de","fr"]
 
 804 function! ToggleSpell()
 
 805   if !exists("b:myLang")
 
 808   execute "setlocal spell!"
 
 810     echo "setlocal spelllang=" g:myLangList[b:myLang]
 
 814 function! SwitchSpell()
 
 815   if !exists("b:myLang")
 
 819     let b:myLang=b:myLang+1
 
 820     if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
 
 822   execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
 
 823   echo "setlocal spelllang=" g:myLangList[b:myLang]
 
 826 nnoremap <silent> coS :call SwitchSpell()<CR>
 
 827 " fix spelling with first choice
 
 828 nnoremap <Leader>f 1z=
 
 830 " gitdir or home {{{2
 
 832 " http://git.io/v3GAV
 
 833 function! FindGitDirOrHome()
 
 834   let filedir = expand('%:p:h')
 
 835   if isdirectory(filedir)
 
 836     let cmd = 'bash -c "(cd ' . filedir . '; git rev-parse --show-toplevel 2>/dev/null)"'
 
 837     let gitdir = system(cmd)
 
 838     if strlen(gitdir) == 0
 
 848 command! Cdr execute('cd ' . FindGitDirOrHome())
 
 850 command! LCdr execute('lcd ' . FindGitDirOrHome())
 
 852 " vim:set et sw=2 ts=2 tw=78: