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 " fix some issue with vim-clang-format not finding .clang-format
 
  35 let g:clang_format#detect_style_file = 1
 
  36 Plug 'vimwiki/vimwiki', { 'branch': 'dev' }
 
  37 Plug 'scrooloose/syntastic'
 
  38 Plug 'sgeb/vim-diff-fold'
 
  39 Plug 'shougo/unite.vim'
 
  40 Plug 'shougo/vimproc.vim', {'do': 'make'}
 
  42 Plug 'thinca/vim-qfreplace'
 
  43 Plug 'tomtom/tcomment_vim'
 
  44 Plug 'tpope/vim-abolish'
 
  45 Plug 'tpope/vim-endwise'
 
  46 Plug 'tpope/vim-eunuch'
 
  47 Plug 'tpope/vim-fugitive'
 
  48 Plug 'tpope/vim-repeat'
 
  49 Plug 'tpope/vim-surround'  "investigate vim-sandwich
 
  50 Plug 'tpope/vim-unimpaired'
 
  51 Plug 'tweekmonster/spellrotate.vim'
 
  52 Plug 'valloric/youcompleteme', { 'do': './install.py --clang-completer' }
 
  53 Plug 'vim-scripts/mediawiki.vim'
 
  54 Plug 'vim-scripts/replacewithregister'
 
  55 Plug 'vim-scripts/yankring.vim'
 
  58 Plug 'morhetz/gruvbox'
 
  61 Plug 'sirver/ultisnips'
 
  62 Plug 'honza/vim-snippets'
 
  65 Plug 'kana/vim-textobj-user'
 
  66 Plug 'julian/vim-textobj-variable-segment'
 
  67 Plug 'sgur/vim-textobj-parameter'
 
  68 Plug 'kana/vim-operator-user'
 
  71 " find an alternative (latex-box? Automatic Latex Plugin?)
 
  72 Plug 'vim-latex/vim-latex'
 
  74 " needs editing colorscheme
 
  75 " Plug 'jeaye/color_coded'
 
  76 " Check LucHermites plugins: https://github.com/LucHermitte/lh-cpp
 
  81 filetype plugin indent on
 
  86 let g:gruvbox_contrast_dark  = 'hard'
 
  87 let g:gruvbox_contrast_light = 'soft'
 
  89 " override the background to be black
 
  90 highligh Normal ctermbg=None
 
  93 " moving around, searching and patterns {{{2
 
  94 set incsearch           " show match for partly typed search command
 
  95 set ignorecase          " ignore case when using a search pattern
 
  96 set smartcase           " override 'ignorecase' when pattern has upper case characters
 
  97 set hlsearch            " highlight all matches for the last used search pattern
 
  99 set nostartofline       " don't move the cursor to the first non-blank char of a line
 
 102 set path+=../include/
 
 103 set path+=/usr/include/c++/*
 
 105 " displaying text {{{2
 
 106 set nowrap                      " long lines wrap
 
 107 set linebreak                   " wrap long lines at a character in 'breakat'
 
 108 set showbreak=↪                 " show these chars for wrapped lines
 
 109 set breakindent                 " preserve indentation in wrapped text
 
 111 set lazyredraw                  " don't redraw while executing macros
 
 113 set list                        " show chars defined in 'listchars'
 
 114 set listchars=tab:❭\            " list of strings used for list mode
 
 115 set listchars+=extends:❯,precedes:❮
 
 116 " Only shown when not in insert mode
 
 117 set listchars+=trail:·
 
 120     au InsertEnter * :set listchars-=trail:·
 
 121     au InsertLeave * :set listchars+=trail:·
 
 124 set scrolloff=5                 " number of screen lines to show around the cursor
 
 125 set sidescroll=1                " number of collumns to scroll
 
 126 set sidescrolloff=1             " don't scroll over the listchars
 
 128 set fillchars=diff:⣿,vert:│
 
 130 set nonumber                    " show the line number for each line
 
 131 set norelativenumber            " show the relative line number for each line
 
 133 " syntax, highlighting and spelling {{{2
 
 134 set synmaxcol=800               " don't highlight long lines
 
 136 set dictionary=spell            " list of dictionary files for keyword completion
 
 140 " multiple windows {{{2
 
 141 set laststatus=2                " 0, 1 or 2; when to use a status line for the last window
 
 143 set previewheight=20            " default height for the preview window
 
 147 " set splitbelow                  " a new window is put below of the current one
 
 148 set splitright                  " a new window is put right of the current one
 
 153 " using the mouse {{{2
 
 154 set mouse=rnv                   " list of flags for using the mouse
 
 155 set ttymouse=xterm              " type of mouse
 
 157 " messages and info {{{2
 
 158 set showcmd         " Show (partial) command in status line.
 
 159 set ruler           " show the cursor position all the time
 
 160 set confirm         " Ask what to do when closing unsaved documents
 
 161 set shortmess=      " reset option
 
 162 set shortmess+=a    " all abbreviations
 
 163 set shortmess+=o    " overwrite file-written message
 
 164 set shortmess+=O    " file-read message overrides previous
 
 165 set shortmess+=t    " truncate file message at start
 
 166 set shortmess+=T    " truncate other messages in the middle
 
 167 set shortmess+=W    " don't give 'written' or '[w]' when writing a file
 
 168 set shortmess+=A    " ignore swapfile warning
 
 169 set shortmess+=I    " no splash screen
 
 172 set backspace=indent,eol,start  " allow backspacing over everything in insert mode
 
 174 set showmatch                   " Show matching brackets.
 
 176 set nojoinspaces                " don't use two spaces after '.' when joining a line
 
 177 set formatoptions+=j    " Delete comment leader when joining lines
 
 178 set formatoptions+=c    " Autowrap comments using textwidth
 
 179 set formatoptions+=r    " Insert comment leader after hitting <Enter>
 
 180 set formatoptions+=n    " Recognize numbered lists
 
 181 set formatoptions+=q    " Allow formatting of comments with "gq".
 
 182 set formatoptions+=l    " do not wrap lines that have been longer when starting insert mode already
 
 183 set formatoptions+=t    " Auto-wrap text using textwidth
 
 184 set formatoptions-=o    " Do not insert comment leader after hitting o or O in normal mode
 
 186 set nrformats=hex               " number formats recognized for CTRL-A and CTRL-X commands
 
 188 set complete=.       " scan the current buffer ( 'wrapscan' is ignored)
 
 189 set complete+=w      " scan buffers from other windows
 
 190 set complete+=b      " scan other loaded buffers that are in the buffer list
 
 191 set complete+=u      " scan the unloaded buffers that are in the buffer list
 
 192 set complete+=t      " scan tags
 
 193 set complete+=i      " scan current and included files
 
 194 set complete+=kspell " use the currently active spell checking |spell|
 
 196 " whether to use a popup menu for Insert mode completion
 
 197 set completeopt=longest,menuone,preview
 
 199 " tabs and indent {{{2
 
 200 set shiftwidth=4                " number of spaces used for each step of (auto)indent
 
 201 set smarttab                    " a <Tab> in an indent inserts 'shiftwidth' spaces
 
 202 set softtabstop=4               " if non-zero, number of spaces to insert for a <Tab>
 
 203 set shiftround                  " round to 'shiftwidth' for "<<" and ">>"
 
 204 set expandtab                   " expand <Tab> to spaces in Insert mode
 
 207 set pastetoggle=<F11>           " key sequence to toggle paste mode
 
 210 set foldmethod=marker           " folding type
 
 211 set foldlevelstart=0            " value for 'foldlevel' when starting to edit a file
 
 213 " open folds when jumping to line
 
 216 set viewoptions=cursor          " save cursor position
 
 217 set viewoptions+=folds          " save folds
 
 220 set diffopt+=filler         " show filler lines
 
 221 set diffopt+=vertical       " always vertical split
 
 222 set diffopt+=context:10     " 10 lines context between changes
 
 224 " reading and writing files {{{2
 
 225 set modeline                    " read modelines
 
 226 set modelines=2                 " only check first/last 2 lines
 
 228 set writebackup                 " write a backup file before overwriting a file
 
 229 set backup                      " keep a backup after owerwriting a file
 
 230 set backupdir=$XDG_CACHE_HOME/vim/backup//
 
 232 set backupskip+=.netrc          " skip netrc
 
 233 set backupskip+=/dev/shm/pass*  " skip passwordstore files
 
 235 set undofile                    " persistent undo history
 
 236 set undodir=$XDG_CACHE_HOME/vim/undo//
 
 240     au BufWritePre .netrc         setlocal noundofile
 
 241     au BufWritePre /dev/shm/pass* setlocal noundofile
 
 242     au BufWritePre /tmp/*         setlocal noundofile
 
 245 set autowrite                   " automatically write a file when leaving a modified buffer
 
 246 set autoread                    " automatically read a file that has been modified
 
 250 set directory=$XDG_CACHE_HOME/vim/swap//
 
 252 " command line editing {{{2
 
 253 set history=5000                " how many command lines are remembered
 
 254 set wildmenu                    " command-line completion shows a list of matches
 
 255 set wildmode=longest:full,full  " specifies how command line completion works
 
 256 set wildignorecase              " ignore case when completing file names
 
 258 set wildignore+=.hg,.git,.svn                    " Version control
 
 259 set wildignore+=*.aux,*.out,*.toc                " LaTeX intermediate files
 
 260 set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg   " binary images
 
 261 set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
 
 262 set wildignore+=*.spl                            " compiled spelling word lists
 
 263 set wildignore+=*.sw?                            " Vim swap files
 
 264 set wildignore+=*.luac                           " Lua byte code
 
 265 set wildignore+=*.pyc                            " Python byte code
 
 266 set wildignore+=*.orig                           " Merge resolution files
 
 268 " running make and jumping to errors {{{2
 
 269 set makeprg=make\ -w     " print changing directories
 
 271 set grepprg=ag\ --vimgrep\ $*
 
 273 " language specific {{{2
 
 274 set isfname-==    " don't treat `=` as being part of filenames
 
 277 set virtualedit+=block     " let cursor move past last char in <C-V> mode
 
 278 set virtualedit+=onemore   " allow the cursor to move just past the end of the line
 
 279 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
 
 281 set viewdir=$XDG_CACHE_HOME/vim/view//
 
 283 set sessionoptions+=unix,slash  " damn windows and it's silly ways
 
 286 " Resize splits when the window is resized {{{2
 
 289     autocmd VimResized * :wincmd =
 
 292 " Only show cursorline in the current window and in normal mode {{{2
 
 295     au WinLeave,InsertEnter * set nocursorline
 
 296     au WinEnter,InsertLeave * set cursorline
 
 299 " Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
 
 302     au StdinReadPost * :set buftype=nofile
 
 305 " Jump to last known cursor position {{{2
 
 308     " blacklist certain filetype
 
 309     let blacklist = ['gitcommit']
 
 310     autocmd BufReadPost *
 
 311                 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
 
 312                 \   exe "normal! g`\"" |
 
 316 " Check for file modifications automatically {{{2
 
 317 " (current buffer only)
 
 318 " Use :NoAutoChecktime to disable it (uses b:autochecktime)
 
 319 fun! MyAutoCheckTime()
 
 320   " only check timestamp for normal files
 
 321   if &buftype != '' | return | endif
 
 322   if ! exists('b:autochecktime') || b:autochecktime
 
 324     let b:autochecktime = 1
 
 327 augroup MyAutoChecktime
 
 329   au FocusGained,BufEnter,CursorHold,InsertEnter * call MyAutoCheckTime()
 
 331 command! NoAutoChecktime let b:autochecktime=0
 
 332 command! ToggleAutoChecktime let b:autochecktime=!get(b:, 'autochecktime', 0) | echom "b:autochecktime:" b:autochecktime
 
 336   au TerminalOpen * if &buftype == 'terminal' | setlocal bufhidden=hide | endif
 
 341 " allow both <space> and \ to be <leader>
 
 345 nnoremap <leader>r :make!<cr>
 
 346 nnoremap <leader><cr> :make!<cr>
 
 349 nnoremap <silent> <Leader>/ :silent nohl<CR>
 
 352 nnoremap <leader>[ :tabprev<cr>
 
 353 nnoremap <leader>] :tabnext<cr>
 
 355 " paste from selection
 
 356 nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
 
 357 " paste from clipboard
 
 358 nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
 
 360 " strip trailing whitespace
 
 361 function! StripWhitespace(line1, line2, ...)  " {{{2
 
 362   let s_report = &report
 
 364   let pattern = a:0 ? a:1 : '\s\+$'
 
 365   let oldview = winsaveview()
 
 366   exe 'keepjumps keeppatterns '.a:line1.','.a:line2.'substitute/'.pattern.'//e'
 
 367   if oldview != winsaveview()
 
 370   call winrestview(oldview)
 
 371   let &report = s_report
 
 373 command! -range=% -nargs=0 -bar Untrail keepjumps call StripWhitespace(<line1>,<line2>)
 
 374 nnoremap <silent> <leader>ww :Untrail<CR>
 
 377 vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
 
 378 nnoremap <leader>S ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
 
 380 " jump to last cursor position
 
 383 " Select (charwise) the contents of the current line, excluding indentation.
 
 387 nnoremap U :syntax sync fromstart<cr>:AirlineRefresh<cr>:redraw!<cr>
 
 390 " nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
 
 391 " nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
 
 398 " display the number of matches for the last search
 
 399 nmap <Leader># :%s:<C-R>/::gn<CR>
 
 401 " center cursor after search and open folds
 
 405 " same when jumping around
 
 408 nnoremap <c-o> <c-o>zzzv
 
 409 nnoremap <c-i> <c-i>zzzv
 
 411 " Not using the default mappings of 'To line from top/bottom'
 
 417 " Heresy, emacs insert bindings
 
 418 inoremap <C-A> <Esc>I
 
 419 inoremap <C-E> <Esc>A
 
 420 cnoremap <C-A> <Home>
 
 423 " proper movement when lines are wrapped
 
 424 noremap <silent><expr> j (v:count == 0 ? 'gj' : 'j')
 
 425 noremap <silent><expr> k (v:count == 0 ? 'gk' : 'k')
 
 431 noremap  <Right> <NOP>
 
 433 inoremap <Down>  <NOP>
 
 434 inoremap <Left>  <NOP>
 
 435 inoremap <Right> <NOP>
 
 437 cnoremap <Down>  <NOP>
 
 438 cnoremap <Left>  <NOP>
 
 439 cnoremap <Right> <NOP>
 
 441 cnoremap <C-J>   <Down>
 
 442 cnoremap <C-H>   <Left>
 
 443 cnoremap <C-L>   <Right>
 
 445 " close all folds open fold in cursor
 
 448 map <F1> :ls<CR>:b<space>
 
 450 " move between windows (skip previewwindow)
 
 451 nnoremap <silent> <C-L> <C-W>w<C-W>:if &previewwindow \| wincmd w \| endif<CR>
 
 452 nnoremap <silent> <C-H> <C-W>W<C-W>:if &previewwindow \| wincmd W \| endif<CR>
 
 453 tnoremap <silent> <C-L> <C-W>w<C-W>:if &previewwindow \| wincmd w \| endif<CR>
 
 454 tnoremap <silent> <C-H> <C-W>W<C-W>:if &previewwindow \| wincmd W \| endif<CR>
 
 456 "xterm mouse with middleclick paste
 
 457 nnoremap <MiddleMouse> i<MiddleMouse>
 
 458 vnoremap <MiddleMouse> s<MiddleMouse>
 
 460 " fix legacy vi inconsistency
 
 465 " allow repeat operator on visual
 
 466 vnoremap . :normal .<CR>
 
 468 " add line without changing position or leaving mode
 
 469 noremap <silent> <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
 
 470 noremap <silent> <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
 
 472 " Don't use Ex mode, use Q for formatting
 
 475 " break undo sequence before removing word
 
 476 inoremap <C-W> <C-G>u<C-W>
 
 478 nnoremap coe :set <C-R>=&expandtab ? 'noexpandtab' : 'expandtab'<CR><CR>
 
 479 nnoremap [oe :set expandtab<CR>
 
 480 nnoremap ]oe :set noexpandtab<CR>
 
 482 for idt in range(1,8)
 
 483   exe 'nnoremap co'.idt.' :setlocal tabstop='.idt.' shiftwidth='.idt.' softtabstop='.idt.'<CR>'
 
 486 " toggle auto format of text
 
 487 nnoremap coa :set <C-R>=&formatoptions =~ "a" ? 'formatoptions-=a' : 'formatoptions+=a'<CR><CR>
 
 488 nnoremap [oa :set formatoptions+=a<CR>
 
 489 nnoremap ]oa :set formatoptions-=a<CR>
 
 491 " space will toggle current fold in normal mode
 
 492 nnoremap <leader><Space> za
 
 493 " create folds around visual selection
 
 494 vnoremap <leader><Space> zf
 
 497 cabbrev w!! SudoWrite
 
 499 " uppercase previous word
 
 500 inoremap <C-C> <Esc>gUiwgi
 
 502 " http://git.io/v3ZeU
 
 503 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>
 
 505 " plugins options {{{1
 
 507 let g:airline#extensions#whitespace#enabled = 1
 
 508 let g:airline#extensions#tabline#enabled = 1
 
 509 let g:airline_powerline_fonts = 1
 
 512 let g:checkattach_filebrowser = 'ranger'
 
 513 let g:checkattach_once = 'y'
 
 516 let delimitMate_expand_cr = 2
 
 517 let g:delimitMate_expand_space = 1
 
 520 nnoremap <silent> <Leader>ff :FSHere<CR>
 
 521 nnoremap <silent> <Leader>fl :FSRight<CR>
 
 522 nnoremap <silent> <Leader>fh :FSLeft<CR>
 
 523 nnoremap <silent> <Leader>fj :FSBelow<CR>
 
 524 nnoremap <silent> <Leader>fk :FSAbove<CR>
 
 525 nnoremap <silent> <Leader>fL :FSSplitRight<CR>
 
 526 nnoremap <silent> <Leader>fH :FSSplitLeft<CR>
 
 527 nnoremap <silent> <Leader>fJ :FSSplitBelow<CR>
 
 528 nnoremap <silent> <Leader>fK :FSSplitAbove<CR>
 
 531 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
 
 532 " delete fugitive buffers when closed
 
 533 autocmd BufReadPost fugitive://* set bufhidden=delete
 
 535 nnoremap <silent> <leader>gs :Gstatus<CR>
 
 536 nnoremap <silent> <leader>gd :Gdiff<CR>
 
 537 nnoremap <silent> <leader>gc :Gcommit -v<CR>
 
 538 nnoremap <silent> <leader>ga :Gwrite<cr>
 
 539 nnoremap <silent> <leader>gb :Gblame<cr>
 
 541 augroup fugitive_gstatus
 
 543     autocmd BufWinEnter */.git/index resize 16
 
 547 nnoremap <F7> :GundoToggle<CR>
 
 550 let g:indent_guides_default_mapping = 0
 
 551 let g:indent_guides_guide_size = 1
 
 552 nmap <silent> cog <Plug>IndentGuidesToggle
 
 553 nmap <silent> [og <Plug>IndentGuidesEnable
 
 554 nmap <silent> ]og <Plug>IndentGuidesDisable
 
 556 " close-another-window {{{2
 
 557 nnoremap <silent> <C-W>c  <NOP>
 
 558 nnoremap <silent> <C-W>cc <C-W>c
 
 559 nnoremap <silent> <C-W>ch :CloseLeftWindow<CR>
 
 560 nnoremap <silent> <C-W>cl :CloseRightWindow<CR>
 
 561 nnoremap <silent> <C-W>cj :CloseBelowWindow<CR>
 
 562 nnoremap <silent> <C-W>ck :CloseAboveWindow<CR>
 
 566 let g:pymode_rope_completion = 0
 
 567 let g:pymode_rope = 0
 
 569 let g:pymode_folding = 1
 
 570 let g:pymode_lint_ignore = "E221,E266,E501"
 
 571 let g:pymode_lint_cwindow = 0           " don't open cwindow when linting
 
 572 let g:pymode_syntax_space_errors = 0    " don't bother me when I'm typing
 
 575 " disable '[ mappings
 
 577 let g:SignatureMap = {
 
 578   \ 'GotoNextLineAlpha'  :  "",
 
 579   \ 'GotoPrevLineAlpha'  :  "",
 
 580   \ 'GotoNextSpotAlpha'  :  "",
 
 581   \ 'GotoPrevSpotAlpha'  :  "",
 
 585 let g:switch_mapping = "<Leader>s"
 
 588 nmap <silent> z] <Plug>(SpellRotateForward)
 
 589 nmap <silent> z[ <Plug>(SpellRotateBackward)
 
 590 vmap <silent> z] <Plug>(SpellRotateForwardV)
 
 591 vmap <silent> z[ <Plug>(SpellRotateBackwardV)
 
 594 let g:syntastic_enable_highlighting = 0
 
 595 let g:syntastic_error_symbol='E'
 
 596 let g:syntastic_style_error_symbol='S'
 
 597 let g:syntastic_warning_symbol='W'
 
 598 let g:syntastic_style_warning_symbol='S'
 
 599 let g:syntastic_always_populate_loc_list=1
 
 600 nmap <silent> <leader>y :SyntasticCheck<cr>
 
 602 let g:syntastic_cpp_clang_tidy_post_args = "-p build*"
 
 605   let g:syntastic_check_on_open=1
 
 609 map <F5> :TagbarToggle<cr>
 
 610 let g:tagbar_sort = 0
 
 611 let g:tagbar_compact = 1
 
 612 let g:tagbar_autoshowtag = 1
 
 613 let g:tagbar_width = 25
 
 614 let g:tagbar_iconchars = ['+', '-']
 
 617 let g:tcomment_textobject_inlinecomment = 'gic'
 
 618 let g:tcomment#filetype#guess = 0
 
 621 let g:UltiSnipsEditSplit = 'vertical'
 
 622 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
 
 624   let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
 
 626 let g:UltiSnipsExpandTrigger       = "<tab>"
 
 627 let g:UltiSnipsJumpForwardTrigger  = "<tab>"
 
 628 let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
 
 630 " UltiSnips completion function that tries to expand a snippet. If there's no
 
 631 " snippet for expanding, it checks for completion window and if it's shown,
 
 632 " selects first element. If there's no completion window it tries to jump to
 
 633 " next placeholder. If there's no placeholder it just returns TAB key
 
 634 " https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-15451411
 
 635 function! g:UltiSnips_Complete()
 
 636     call UltiSnips#ExpandSnippet()
 
 637     if g:ulti_expand_res == 0
 
 641             call UltiSnips#JumpForwards()
 
 642             if g:ulti_jump_forwards_res == 0
 
 649 au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
 
 650 let g:UltiSnipsListSnippets="<c-e>"
 
 653 call unite#filters#matcher_default#use(['matcher_fuzzy'])
 
 654 call unite#custom#profile('default', 'context', {
 
 656             \ 'direction': 'botright'
 
 659 nnoremap [unite] <Nop>
 
 660 nmap <leader>u [unite]
 
 661 nnoremap [unite]u :UniteResume<CR>
 
 662 nnoremap <silent> [u :UnitePrevious<CR>
 
 663 nnoremap <silent> ]u :UniteNext<CR>
 
 666 " seems not respected
 
 667 let g:unite_source_grep_max_candidates = 2000
 
 669     " Use ag in unite grep source.
 
 670     let g:unite_source_grep_command = 'ag'
 
 671     let g:unite_source_grep_default_opts = '--smart-case --vimgrep --ignore ''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'''
 
 672     let g:unite_source_grep_recursive_opt = ''
 
 674 nnoremap <silent> [unite]a :<C-u>Unite grep:.::
\12\17<CR>
 
 675 nnoremap <silent> [unite]A :<C-u>Unite grep:.:-w:
\12\17<CR>
 
 676 command! -nargs=1 Ag Unite grep:.::<args>
 
 678 " unite-file_rec {{{3
 
 680     " Use ag in unite rec source
 
 681     let g:unite_source_rec_async_command = ['ag', '--follow', '--nocolor', '--nogroup', '-g', '']
 
 683 nnoremap <silent> [unite]f :<C-u>Unite -start-insert file_rec/async<CR>
 
 684 call unite#custom#source('file_rec/async', 'sorters', 'sorter_selecta')
 
 687 call unite#custom#default_action('buffer', 'open')
 
 688 nnoremap <silent> [unite]b :<C-u>Unite buffer:-<CR>
 
 691 let g:unite_source_menu_menus = {}
 
 692 let g:unite_source_menu_menus.fugitive = { 'description' : 'fugitive menu'}
 
 693 let g:unite_source_menu_menus.fugitive.command_candidates = {
 
 694             \ 'Gstatus <Leader>gs' : 'Gstatus',
 
 695             \ 'Gcommit -v <Leader>gc' : 'Gcommit -v',
 
 699 nnoremap <silent> <leader>gg :<C-u>Unite menu:fugitive<CR>
 
 701 let g:unite_source_history_yank_enable = 1
 
 702 nnoremap <silent> [unite]p :<C-u>Unite history/yank<CR>
 
 705 nnoremap <silent> <leader>p :YRShow<cr>
 
 706 let g:yankring_history_dir = expand('$XDG_CACHE_HOME/vim')
 
 707 let g:yankring_replace_n_pkey = ''
 
 708 let g:yankring_replace_n_nkey = ''
 
 710 " map Y to y$ for the yank ring
 
 711 function! YRRunAfterMaps()
 
 712     nnoremap Y   :<C-U>YRYankCount 'y$'<CR>
 
 716 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
 
 717 let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
 
 718 let g:ycm_extra_conf_vim_data = ['getcwd()']
 
 719 let g:ycm_add_preview_to_completeopt = 1
 
 720 let g:ycm_complete_in_comments = 1
 
 721 let g:ycm_complete_in_strings  = 1
 
 722 let g:ycm_autoclose_preview_window_after_insertion = 0
 
 724 " vim-easy-align {{{2
 
 725 " start interactive EasyAlign in visual mode
 
 726 vmap <Enter> <Plug>(EasyAlign)
 
 727 nmap ga <Plug>(EasyAlign)
 
 730 let g:gtest#highlight_failing_tests = 0
 
 732 nnoremap <Leader>tt :GTestRun<CR>
 
 733 nnoremap <Leader>ta :GTestCase *<CR>:GTestName *<CR>:GTestRun<CR>
 
 734 nnoremap <Leader>tu :GTestRunUnderCursor<CR>
 
 737 let g:vim_json_syntax_conceal = 0
 
 740 let g:tex_flavor='latex'
 
 741 let g:Tex_DefaultTargetFormat='pdf'
 
 742 let g:Tex_MultipleCompileFormats='pdf'
 
 745 let g:sneak#streak = 1
 
 746 let g:sneak#target_labels = "aoeuisnthdpylrcgfqjkxzmwvz" " dvorak
 
 747 let g:sneak#use_ic_scs = 1  " follow 'ignorecase' and 'smartcase'
 
 764 let g:vimwiki_list = [{'path': '$XDG_DATA_HOME/vimwiki'}]
 
 765 let g:vimwiki_auto_chdir = 1
 
 767   au! BufRead            $XDG_DATA_HOME/vimwiki/index.wiki   !git -C "%:p:h" pull -q
 
 768   au! BufRead,BufNewFile $XDG_DATA_HOME/vimwiki/diary/*.wiki !git -C "%:p:h" pull -q
 
 769   au! BufWritePost       $XDG_DATA_HOME/vimwiki/*.wiki       exe '!git add "<afile>";git commit -qm"' . strftime("%FT%R") . '";git push -q'
 
 774 " Convenient command to see the difference between the current buffer and the
 
 775 " file it was loaded from, thus the changes you made.
 
 776 " Only define it when not defined already.
 
 777 if !exists(":DiffOrig")
 
 778   command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
 
 779                   \ | wincmd p | diffthis
 
 783 function! SortLinesOpFunc(...)
 
 786 nnoremap <silent> gs :<C-U>set operatorfunc=SortLinesOpFunc<CR>g@
 
 787 vnoremap <silent> gs :sort<cr>
 
 790 function! EditConfig(what)
 
 791     let l:dir = split(&runtimepath,',')[0]
 
 793         let l:file = expand($MYVIMRC)
 
 794     elseif ! isdirectory(globpath(l:dir, a:what))
 
 795         echoe a:what." is not valid!"
 
 796     elseif empty(&filetype)
 
 797         echoe 'filetype is empty!'
 
 799         let l:file = l:dir.'/'.a:what.'/'.&filetype.'.vim'
 
 802     execute ':vsplit '.file
 
 805 nmap <leader>ev :call EditConfig('vimrc')<CR>
 
 806 nmap <leader>ef :call EditConfig('ftplugin')<CR>
 
 807 nmap <leader>es :call EditConfig('syntax')<CR>
 
 808 nmap <leader>ei :call EditConfig('indent')<CR>
 
 809 nmap <leader>eu :UltiSnipsEdit<CR>:lcd %:p:h<CR>
 
 812 " http://tex.stackexchange.com/a/52932
 
 813 let g:myLangList=["en_gb","en_us","de","fr"]
 
 815 function! ToggleSpell()
 
 816   if !exists("b:myLang")
 
 819   execute "setlocal spell!"
 
 821     echo "setlocal spelllang=" g:myLangList[b:myLang]
 
 825 function! SwitchSpell()
 
 826   if !exists("b:myLang")
 
 830     let b:myLang=b:myLang+1
 
 831     if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
 
 833   execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
 
 834   echo "setlocal spelllang=" g:myLangList[b:myLang]
 
 837 nnoremap <silent> coS :call SwitchSpell()<CR>
 
 838 " fix spelling with first choice
 
 839 nnoremap <Leader>f 1z=
 
 841 " gitdir or home {{{2
 
 843 " http://git.io/v3GAV
 
 844 function! FindGitDirOrHome()
 
 845   let filedir = expand('%:p:h')
 
 846   if isdirectory(filedir)
 
 847     let cmd = 'bash -c "(cd ' . filedir . '; git rev-parse --show-toplevel 2>/dev/null)"'
 
 848     let gitdir = system(cmd)
 
 849     if strlen(gitdir) == 0
 
 859 command! Cdr execute('cd ' . FindGitDirOrHome())
 
 861 command! LCdr execute('lcd ' . FindGitDirOrHome())
 
 863 " vim:set et sw=2 ts=2 tw=78: