]> git.rmz.io Git - dotfiles.git/blob - vim/vimrc
vim: don't set any gcc flags
[dotfiles.git] / vim / vimrc
1 " My vimrc.
2 "
3 " Author: Samir Benmendil <samir.benmendil[at]gmail[dot]com>
4 "
5
6 " runtimepath {{{1
7 set runtimepath ^=$XDG_CONFIG_HOME/vim
8 set runtimepath +=$XDG_CONFIG_HOME/vim/after
9
10 " plugins {{{1
11 " remove all autocommands
12 autocmd!
13
14 call plug#begin('$XDG_DATA_HOME/vim')
15 " This does not update vim-plug, use PlugUpgrade instead
16 Plug 'junegunn/vim-plug'
17
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'
24 Plug 'elzr/vim-json'
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'}
41 Plug 'sjl/gundo.vim'
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-speeddating'
50 Plug 'tpope/vim-surround' "investigate vim-sandwich
51 Plug 'tpope/vim-unimpaired'
52 Plug 'tweekmonster/spellrotate.vim'
53 Plug 'valloric/youcompleteme', { 'do': './install.py --clangd-completer --clang-completer' }
54 Plug 'vim-scripts/mediawiki.vim'
55 Plug 'vim-scripts/replacewithregister'
56 Plug 'vim-scripts/yankring.vim'
57 Plug 'wincent/loupe'
58
59 " colorschemes
60 Plug 'morhetz/gruvbox'
61
62 " snippets
63 Plug 'sirver/ultisnips'
64 Plug 'honza/vim-snippets'
65
66 " text objects
67 Plug 'kana/vim-textobj-user'
68 Plug 'julian/vim-textobj-variable-segment'
69 Plug 'sgur/vim-textobj-parameter'
70 Plug 'kana/vim-operator-user'
71
72 " staging
73 " Check LucHermites plugins: https://github.com/LucHermitte/lh-cpp
74 Plug 'dense-analysis/ale' " {{{2
75 let g:ale_echo_msg_format = '[%linter%] %code: %%s'
76 let g:ale_c_parse_compile_commands = 1
77 let g:ale_cpp_parse_compile_commands = 1
78 " don't use loclist as it's being populated by ycm
79 " (might want to enable for other filetypes)
80 let g:ale_set_loclist = 0
81 let g:ale_cpp_gcc_options = ''
82 let g:ale_linters_ignore = { 'cpp': ['clangd', 'clangtidy', 'clang'] }
83
84 Plug 'git@github.com:/ram-z/vim-orgmode', { 'branch': 'dev' } " {{{2
85 Plug 'vim-scripts/syntaxrange'
86
87 let g:org_agenda_files = ['~/org/*.org']
88
89 call plug#end()
90
91 filetype plugin indent on
92
93 " colorscheme {{{1
94 syntax on
95 set background=dark
96 let g:gruvbox_contrast_dark = 'hard'
97 let g:gruvbox_contrast_light = 'soft'
98 colorscheme gruvbox
99 " override the background to be black
100 highligh Normal ctermbg=None
101
102 " options {{{1
103 " moving around, searching and patterns {{{2
104 set incsearch " show match for partly typed search command
105 set ignorecase " ignore case when using a search pattern
106 set smartcase " override 'ignorecase' when pattern has upper case characters
107 set hlsearch " highlight all matches for the last used search pattern
108
109 set nostartofline " don't move the cursor to the first non-blank char of a line
110 set path+=.
111 set path+=include/
112 set path+=../include/
113 set path+=/usr/include/c++/*
114
115 " displaying text {{{2
116 set nowrap " long lines wrap
117 set linebreak " wrap long lines at a character in 'breakat'
118 set showbreak=↪ " show these chars for wrapped lines
119 set breakindent " preserve indentation in wrapped text
120
121 set lazyredraw " don't redraw while executing macros
122
123 set list " show chars defined in 'listchars'
124 set listchars=tab:❭\ " list of strings used for list mode
125 set listchars+=extends:❯,precedes:❮
126 " Only shown when not in insert mode
127 set listchars+=trail:·
128 augroup trailing
129 au!
130 au InsertEnter * :set listchars-=trail:·
131 au InsertLeave * :set listchars+=trail:·
132 augroup END
133
134 set scrolloff=5 " number of screen lines to show around the cursor
135 set sidescroll=1 " number of collumns to scroll
136 set sidescrolloff=1 " don't scroll over the listchars
137
138 set fillchars=diff:⣿,vert:│
139
140 set nonumber " show the line number for each line
141 set norelativenumber " show the relative line number for each line
142
143 " syntax, highlighting and spelling {{{2
144 set synmaxcol=800 " don't highlight long lines
145
146 set dictionary=spell " list of dictionary files for keyword completion
147
148 set colorcolumn=+1
149
150 " multiple windows {{{2
151 set laststatus=2 " 0, 1 or 2; when to use a status line for the last window
152
153 set previewheight=20 " default height for the preview window
154
155 set hidden
156
157 " set splitbelow " a new window is put below of the current one
158 set splitright " a new window is put right of the current one
159
160 " terminal {{{2
161 set ttyfast
162
163 " using the mouse {{{2
164 set mouse=rnv " list of flags for using the mouse
165 set ttymouse=xterm " type of mouse
166
167 " messages and info {{{2
168 set showcmd " Show (partial) command in status line.
169 set ruler " show the cursor position all the time
170 set confirm " Ask what to do when closing unsaved documents
171 set shortmess= " reset option
172 set shortmess+=a " all abbreviations
173 set shortmess+=o " overwrite file-written message
174 set shortmess+=O " file-read message overrides previous
175 set shortmess+=t " truncate file message at start
176 set shortmess+=T " truncate other messages in the middle
177 set shortmess+=W " don't give 'written' or '[w]' when writing a file
178 set shortmess+=A " ignore swapfile warning
179 set shortmess+=I " no splash screen
180
181 " editing text {{{2
182 set backspace=indent,eol,start " allow backspacing over everything in insert mode
183
184 set showmatch " Show matching brackets.
185
186 set nojoinspaces " don't use two spaces after '.' when joining a line
187 set formatoptions+=j " Delete comment leader when joining lines
188 set formatoptions+=c " Autowrap comments using textwidth
189 set formatoptions+=r " Insert comment leader after hitting <Enter>
190 set formatoptions+=n " Recognize numbered lists
191 set formatoptions+=q " Allow formatting of comments with "gq".
192 set formatoptions+=l " do not wrap lines that have been longer when starting insert mode already
193 set formatoptions+=t " Auto-wrap text using textwidth
194 set formatoptions-=o " Do not insert comment leader after hitting o or O in normal mode
195
196 set nrformats=hex " number formats recognized for CTRL-A and CTRL-X commands
197
198 set complete=. " scan the current buffer ( 'wrapscan' is ignored)
199 set complete+=w " scan buffers from other windows
200 set complete+=b " scan other loaded buffers that are in the buffer list
201 set complete+=u " scan the unloaded buffers that are in the buffer list
202 set complete+=t " scan tags
203 set complete+=i " scan current and included files
204 set complete+=kspell " use the currently active spell checking |spell|
205
206 " whether to use a popup menu for Insert mode completion
207 set completeopt=longest,menuone,preview
208
209 " tabs and indent {{{2
210 set shiftwidth=4 " number of spaces used for each step of (auto)indent
211 set smarttab " a <Tab> in an indent inserts 'shiftwidth' spaces
212 set softtabstop=4 " if non-zero, number of spaces to insert for a <Tab>
213 set shiftround " round to 'shiftwidth' for "<<" and ">>"
214 set expandtab " expand <Tab> to spaces in Insert mode
215 set autoindent
216
217 set pastetoggle=<F11> " key sequence to toggle paste mode
218
219 " folding {{{2
220 set foldmethod=marker " folding type
221 set foldlevelstart=0 " value for 'foldlevel' when starting to edit a file
222
223 " open folds when jumping to line
224 set foldopen+=jump
225
226 set viewoptions=cursor " save cursor position
227 set viewoptions+=folds " save folds
228
229 " diff mode {{{2
230 set diffopt+=filler " show filler lines
231 set diffopt+=vertical " always vertical split
232 set diffopt+=context:10 " 10 lines context between changes
233
234 " reading and writing files {{{2
235 set modeline " read modelines
236 set modelines=2 " only check first/last 2 lines
237
238 set writebackup " write a backup file before overwriting a file
239 set backup " keep a backup after owerwriting a file
240 set backupdir=$XDG_CACHE_HOME/vim/backup//
241
242 set backupskip+=.netrc " skip netrc
243 set backupskip+=/dev/shm/pass* " skip passwordstore files
244
245 set undofile " persistent undo history
246 set undodir=$XDG_CACHE_HOME/vim/undo//
247
248 augroup undoskip
249 au!
250 au BufWritePre .netrc setlocal noundofile
251 au BufWritePre /dev/shm/pass* setlocal noundofile
252 au BufWritePre /tmp/* setlocal noundofile
253 augroup END
254
255 set autowrite " automatically write a file when leaving a modified buffer
256 set autoread " automatically read a file that has been modified
257
258 " the swap file {{{2
259 set noswapfile
260 set directory=$XDG_CACHE_HOME/vim/swap//
261
262 " command line editing {{{2
263 set history=5000 " how many command lines are remembered
264 set wildmenu " command-line completion shows a list of matches
265 set wildmode=longest:full,full " specifies how command line completion works
266 set wildignorecase " ignore case when completing file names
267
268 set wildignore+=.hg,.git,.svn " Version control
269 set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
270 set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
271 set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
272 set wildignore+=*.spl " compiled spelling word lists
273 set wildignore+=*.sw? " Vim swap files
274 set wildignore+=*.luac " Lua byte code
275 set wildignore+=*.pyc " Python byte code
276 set wildignore+=*.orig " Merge resolution files
277
278 " running make and jumping to errors {{{2
279 set makeprg=make\ -w " print changing directories
280
281 set grepprg=ag\ --vimgrep\ $*
282
283 " language specific {{{2
284 set isfname-== " don't treat `=` as being part of filenames
285
286 " various {{{2
287 set virtualedit+=block " let cursor move past last char in <C-V> mode
288 set virtualedit+=onemore " allow the cursor to move just past the end of the line
289 set viminfo='100,<50,s10,h,n$XDG_CACHE_HOME/vim/viminfo " viminfo defaults but save file in .cache
290
291 set viewdir=$XDG_CACHE_HOME/vim/view//
292
293 set sessionoptions+=unix,slash " damn windows and it's silly ways
294
295 " autocmds {{{1
296 " Resize splits when the window is resized {{{2
297 augroup resize
298 au!
299 autocmd VimResized * :wincmd =
300 augroup END
301
302 " Only show cursorline in the current window and in normal mode {{{2
303 augroup cline
304 au!
305 au WinLeave,InsertEnter * set nocursorline
306 au WinEnter,InsertLeave * set cursorline
307 augroup END
308
309 " Treat buffers from stdin (e.g.: echo foo | vim -) as scratch {{{2
310 augroup ft_stdin
311 au!
312 au StdinReadPost * :set buftype=nofile
313 augroup END
314
315 " Jump to last known cursor position {{{2
316 augroup cursor_pos
317 au!
318 " blacklist certain filetype
319 let blacklist = ['gitcommit']
320 autocmd BufReadPost *
321 \ if index(blacklist, &ft) < 0 && line("'\"") > 1 && line("'\"") <= line("$") |
322 \ exe "normal! g`\"" |
323 \ endif
324 augroup END
325
326 " Check for file modifications automatically {{{2
327 " (current buffer only)
328 " Use :NoAutoChecktime to disable it (uses b:autochecktime)
329 fun! MyAutoCheckTime()
330 " only check timestamp for normal files
331 if &buftype != '' | return | endif
332 if ! exists('b:autochecktime') || b:autochecktime
333 checktime %
334 let b:autochecktime = 1
335 endif
336 endfun
337 augroup MyAutoChecktime
338 au!
339 au FocusGained,BufEnter,CursorHold,InsertEnter * call MyAutoCheckTime()
340 augroup END
341 command! NoAutoChecktime let b:autochecktime=0
342 command! ToggleAutoChecktime let b:autochecktime=!get(b:, 'autochecktime', 0) | echom "b:autochecktime:" b:autochecktime
343
344 augroup terminal
345 au!
346 au TerminalOpen * if &buftype == 'terminal' | setlocal bufhidden=hide | endif
347 augroup END
348
349 " bindings {{{1
350
351 " allow both <space> and \ to be <leader>
352 map <space> <leader>
353
354 " make
355 function! Make()
356 let l:make_dir = ""
357 if exists("b:make_dir")
358 let l:make_dir = "-C ".b:make_dir
359 elseif exists("g:make_dir")
360 let l:make_dir = "-C ".g:make_dir
361 endif
362
363 let l:make_targets = ""
364 if exists("g:make_targets")
365 let l:make_targets = g:make_targets
366 endif
367 execute "make! ".l:make_dir." ".l:make_targets
368 endf
369 nnoremap <leader>r :call Make()<cr>
370
371 " unhighlight search
372 nnoremap <silent> <Leader>/ :silent nohl<CR>
373
374 " Tabs
375 nnoremap <leader>[ :tabprev<cr>
376 nnoremap <leader>] :tabnext<cr>
377
378 " paste from selection
379 nnoremap <leader>p* :silent! set paste<CR>"*p:set nopaste<CR>
380 " paste from clipboard
381 nnoremap <leader>p+ :silent! set paste<CR>"+p:set nopaste<CR>
382
383 " strip trailing whitespace
384 function! StripWhitespace(line1, line2, ...) " {{{2
385 let s_report = &report
386 let &report=0
387 let pattern = a:0 ? a:1 : '\s\+$'
388 let oldview = winsaveview()
389 exe 'keepjumps keeppatterns '.a:line1.','.a:line2.'substitute/'.pattern.'//e'
390 if oldview != winsaveview()
391 redraw
392 endif
393 call winrestview(oldview)
394 let &report = s_report
395 endfunction " }}}2
396 command! -range=% -nargs=0 -bar Untrail keepjumps call StripWhitespace(<line1>,<line2>)
397 nnoremap <silent> <leader>ww :Untrail<CR>
398
399 " Source
400 vnoremap <leader>S y:execute @@<cr>:echo 'Sourced selection.'<cr>
401 nnoremap <leader>S ^vg_y:execute @@<cr>:echo 'Sourced line.'<cr>
402
403 " jump to last cursor position
404 noremap ' `
405
406 " Select (charwise) the contents of the current line, excluding indentation.
407 nnoremap vv ^vg_
408
409 " Unfuck my screen
410 nnoremap U :syntax sync fromstart<cr>:AirlineRefresh<cr>:redraw!<cr>
411
412 " Ranger
413 " nnoremap <leader>r :silent !ranger %:h<cr>:redraw!<cr>
414 " nnoremap <leader>R :silent !ranger<cr>:redraw!<cr>
415
416 " Use sane regexes.
417 nnoremap / /\v
418 vnoremap / /\v
419 cnoremap s/ s/\v
420
421 " display the number of matches for the last search
422 nmap <Leader># :%s:<C-R>/::gn<CR>
423
424 " center cursor after search and open folds
425 nnoremap n nzzzv
426 nnoremap N Nzzzv
427
428 " same when jumping around
429 nnoremap g; g;zzzv
430 nnoremap g, g,zzzv
431 nnoremap <c-o> <c-o>zzzv
432 nnoremap <c-i> <c-i>zzzv
433
434 " Not using the default mappings of 'To line from top/bottom'
435 noremap H ^
436 noremap L $
437 vnoremap H ^
438 vnoremap L g_
439
440 " Heresy, emacs insert bindings
441 inoremap <C-A> <Esc>I
442 inoremap <C-E> <Esc>A
443 cnoremap <C-A> <Home>
444 cnoremap <C-E> <End>
445
446 " proper movement when lines are wrapped
447 noremap <silent><expr> j (v:count == 0 ? 'gj' : 'j')
448 noremap <silent><expr> k (v:count == 0 ? 'gk' : 'k')
449
450 " disable arrows
451 noremap <Up> <NOP>
452 noremap <Down> <NOP>
453 noremap <Left> <NOP>
454 noremap <Right> <NOP>
455 inoremap <Up> <NOP>
456 inoremap <Down> <NOP>
457 inoremap <Left> <NOP>
458 inoremap <Right> <NOP>
459 cnoremap <Up> <NOP>
460 cnoremap <Down> <NOP>
461 cnoremap <Left> <NOP>
462 cnoremap <Right> <NOP>
463 cnoremap <C-K> <Up>
464 cnoremap <C-J> <Down>
465 cnoremap <C-H> <Left>
466 cnoremap <C-L> <Right>
467
468 " close all folds open fold in cursor
469 nnoremap zx zMzxzt
470
471 map <F1> :ls<CR>:b<space>
472
473 " move between windows (skip previewwindow)
474 nnoremap <silent> <C-L> <C-W>w<C-W>:if &previewwindow \| wincmd w \| endif<CR>
475 nnoremap <silent> <C-H> <C-W>W<C-W>:if &previewwindow \| wincmd W \| endif<CR>
476 tnoremap <silent> <C-L> <C-W>w<C-W>:if &previewwindow \| wincmd w \| endif<CR>
477 tnoremap <silent> <C-H> <C-W>W<C-W>:if &previewwindow \| wincmd W \| endif<CR>
478
479 "xterm mouse with middleclick paste
480 nnoremap <MiddleMouse> i<MiddleMouse>
481 vnoremap <MiddleMouse> s<MiddleMouse>
482
483 " fix legacy vi inconsistency
484 nnoremap Y y$
485 " copy to clipboard
486 xnoremap Y "+y
487
488 " allow repeat operator on visual
489 vnoremap . :normal .<CR>
490
491 " add line without changing position or leaving mode
492 noremap <silent> <Leader>o :set paste<CR>m`o<ESC>``:set nopaste<CR>
493 noremap <silent> <Leader>O :set paste<CR>m`O<ESC>``:set nopaste<CR>
494
495 " Don't use Ex mode, use Q for formatting
496 map Q gq
497
498 " break undo sequence before removing word
499 inoremap <C-W> <C-G>u<C-W>
500
501 nnoremap coe :set <C-R>=&expandtab ? 'noexpandtab' : 'expandtab'<CR><CR>
502 nnoremap [oe :set expandtab<CR>
503 nnoremap ]oe :set noexpandtab<CR>
504
505 for idt in range(1,8)
506 exe 'nnoremap co'.idt.' :setlocal tabstop='.idt.' shiftwidth='.idt.' softtabstop='.idt.'<CR>'
507 endfor
508
509 " toggle auto format of text
510 nnoremap coa :set <C-R>=&formatoptions =~ "a" ? 'formatoptions-=a' : 'formatoptions+=a'<CR><CR>
511 nnoremap [oa :set formatoptions+=a<CR>
512 nnoremap ]oa :set formatoptions-=a<CR>
513
514 " space will toggle current fold in normal mode
515 nnoremap <leader><Space> za
516 " create folds around visual selection
517 vnoremap <leader><Space> zf
518
519 " save with sudo
520 cabbrev w!! SudoWrite
521
522 " uppercase previous word
523 inoremap <C-C> <Esc>gUiwgi
524
525 " http://git.io/v3ZeU
526 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>
527
528 " plugins options {{{1
529 " airline {{{2
530 let g:airline#extensions#whitespace#enabled = 1
531 let g:airline#extensions#tabline#enabled = 1
532 let g:airline_powerline_fonts = 1
533
534 " checkattach {{{2
535 let g:checkattach_filebrowser = 'ranger'
536 let g:checkattach_once = 'y'
537
538 " delimitmate {{{2
539 let delimitMate_expand_cr = 2
540 let g:delimitMate_expand_space = 1
541
542 " fswitch {{{2
543 nnoremap <silent> <Leader>ff :FSHere<CR>
544 nnoremap <silent> <Leader>fl :FSRight<CR>
545 nnoremap <silent> <Leader>fh :FSLeft<CR>
546 nnoremap <silent> <Leader>fj :FSBelow<CR>
547 nnoremap <silent> <Leader>fk :FSAbove<CR>
548 nnoremap <silent> <Leader>fL :FSSplitRight<CR>
549 nnoremap <silent> <Leader>fH :FSSplitLeft<CR>
550 nnoremap <silent> <Leader>fJ :FSSplitBelow<CR>
551 nnoremap <silent> <Leader>fK :FSSplitAbove<CR>
552
553 " fugitive {{{2
554 nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<CR>
555 " delete fugitive buffers when closed
556 autocmd BufReadPost fugitive://* set bufhidden=delete
557
558 nnoremap <silent> <leader>gs :Gstatus<CR>
559 nnoremap <silent> <leader>gd :Gdiff<CR>
560 nnoremap <silent> <leader>gc :Gcommit -v<CR>
561 nnoremap <silent> <leader>ga :Gwrite<cr>
562 nnoremap <silent> <leader>gb :Gblame<cr>
563
564 augroup fugitive_gstatus
565 au!
566 autocmd BufWinEnter */.git/index resize 16
567 augroup end
568
569 " Gundo {{{2
570 nnoremap <F7> :GundoToggle<CR>
571
572 " indent-guides {{{2
573 let g:indent_guides_default_mapping = 0
574 let g:indent_guides_guide_size = 1
575 nmap <silent> cog <Plug>IndentGuidesToggle
576 nmap <silent> [og <Plug>IndentGuidesEnable
577 nmap <silent> ]og <Plug>IndentGuidesDisable
578
579 " close-another-window {{{2
580 nnoremap <silent> <C-W>c <NOP>
581 nnoremap <silent> <C-W>cc <C-W>c
582 nnoremap <silent> <C-W>ch :CloseLeftWindow<CR>
583 nnoremap <silent> <C-W>cl :CloseRightWindow<CR>
584 nnoremap <silent> <C-W>cj :CloseBelowWindow<CR>
585 nnoremap <silent> <C-W>ck :CloseAboveWindow<CR>
586
587 " python-mode {{{2
588
589 let g:pymode_rope_completion = 0
590 let g:pymode_rope = 0
591 let g:pymode_run = 0
592 let g:pymode_folding = 1
593 let g:pymode_lint_ignore = "E221,E266,E501"
594 let g:pymode_lint_cwindow = 0 " don't open cwindow when linting
595 let g:pymode_syntax_space_errors = 0 " don't bother me when I'm typing
596
597 " signature {{{2
598 " disable '[ mappings
599
600 let g:SignatureMap = {
601 \ 'GotoNextLineAlpha' : "",
602 \ 'GotoPrevLineAlpha' : "",
603 \ 'GotoNextSpotAlpha' : "",
604 \ 'GotoPrevSpotAlpha' : "",
605 \ }
606
607 " switch
608 let g:switch_mapping = "<Leader>s"
609
610 " spellrotate
611 nmap <silent> z] <Plug>(SpellRotateForward)
612 nmap <silent> z[ <Plug>(SpellRotateBackward)
613 vmap <silent> z] <Plug>(SpellRotateForwardV)
614 vmap <silent> z[ <Plug>(SpellRotateBackwardV)
615
616 " synastic {{{2
617 let g:syntastic_enable_highlighting = 0
618 let g:syntastic_error_symbol='E'
619 let g:syntastic_style_error_symbol='S'
620 let g:syntastic_warning_symbol='W'
621 let g:syntastic_style_warning_symbol='S'
622 let g:syntastic_always_populate_loc_list=1
623 nmap <silent> <leader>y :SyntasticCheck<cr>
624
625 let g:syntastic_cpp_clang_tidy_post_args = "-p build*"
626
627 if ! &diff
628 let g:syntastic_check_on_open=1
629 endif
630
631 " tagbar {{{2
632 map <F5> :TagbarToggle<cr>
633 let g:tagbar_sort = 0
634 let g:tagbar_compact = 1
635 let g:tagbar_autoshowtag = 1
636 let g:tagbar_width = 25
637 let g:tagbar_iconchars = ['+', '-']
638
639 " tcomments {{{2
640 let g:tcomment_textobject_inlinecomment = 'gic'
641 let g:tcomment#filetype#guess = 0
642
643 " ultisnips {{{2
644 let g:UltiSnipsEditSplit = 'vertical'
645 let g:UltiSnipsSnippetsDir = expand("$XDG_CONFIG_HOME/vim/ultisnips")
646 if has('fname_case')
647 let g:UltiSnipsSnippetDirectories = ["UltiSnips", "ultisnips"]
648 endif
649 let g:UltiSnipsExpandTrigger = "<tab>"
650 let g:UltiSnipsJumpForwardTrigger = "<tab>"
651 let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
652
653 " UltiSnips completion function that tries to expand a snippet. If there's no
654 " snippet for expanding, it checks for completion window and if it's shown,
655 " selects first element. If there's no completion window it tries to jump to
656 " next placeholder. If there's no placeholder it just returns TAB key
657 " https://github.com/Valloric/YouCompleteMe/issues/36#issuecomment-15451411
658 function! g:UltiSnips_Complete()
659 call UltiSnips#ExpandSnippet()
660 if g:ulti_expand_res == 0
661 if pumvisible()
662 return "\<C-n>"
663 else
664 call UltiSnips#JumpForwards()
665 if g:ulti_jump_forwards_res == 0
666 return "\<TAB>"
667 endif
668 endif
669 endif
670 return ""
671 endfunction
672 au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
673 let g:UltiSnipsListSnippets="<c-e>"
674
675 " unite {{{2
676 call unite#filters#matcher_default#use(['matcher_fuzzy'])
677 call unite#custom#profile('default', 'context', {
678 \ 'winheight': 20,
679 \ 'direction': 'botright'
680 \ })
681
682 nnoremap [unite] <Nop>
683 nmap <leader>u [unite]
684 nnoremap [unite]u :UniteResume<CR>
685 nnoremap <silent> [u :UnitePrevious<CR>
686 nnoremap <silent> ]u :UniteNext<CR>
687
688 " unite-grep {{{3
689 " seems not respected
690 let g:unite_source_grep_max_candidates = 2000
691 if executable('ag')
692 " Use ag in unite grep source.
693 let g:unite_source_grep_command = 'ag'
694 let g:unite_source_grep_default_opts = '--smart-case --vimgrep --ignore ''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr'''
695 let g:unite_source_grep_recursive_opt = ''
696 end
697 nnoremap <silent> [unite]a :<C-u>Unite grep:.::\12\17<CR>
698 nnoremap <silent> [unite]A :<C-u>Unite grep:.:-w:\12\17<CR>
699 command! -nargs=1 Ag Unite grep:.::<args>
700
701 " unite-file_rec {{{3
702 if executable('ag')
703 " Use ag in unite rec source
704 let g:unite_source_rec_async_command = ['ag', '--follow', '--nocolor', '--nogroup', '-g', '']
705 end
706 nnoremap <silent> [unite]f :<C-u>Unite -start-insert file_rec/async<CR>
707 call unite#custom#source('file_rec/async', 'sorters', 'sorter_selecta')
708
709 " unite-buffer {{{3
710 call unite#custom#default_action('buffer', 'open')
711 nnoremap <silent> [unite]b :<C-u>Unite buffer:-<CR>
712
713 " unite-menu {{{3
714 let g:unite_source_menu_menus = {}
715 let g:unite_source_menu_menus.fugitive = { 'description' : 'fugitive menu'}
716 let g:unite_source_menu_menus.fugitive.command_candidates = {
717 \ 'Gstatus <Leader>gs' : 'Gstatus',
718 \ 'Gcommit -v <Leader>gc' : 'Gcommit -v',
719 \ 'Glog' : 'Glog',
720 \}
721
722 nnoremap <silent> <leader>gg :<C-u>Unite menu:fugitive<CR>
723
724 let g:unite_source_history_yank_enable = 1
725 nnoremap <silent> [unite]p :<C-u>Unite history/yank<CR>
726
727 " yankring {{{2
728 nnoremap <silent> <leader>p :YRShow<cr>
729 let g:yankring_history_dir = expand('$XDG_CACHE_HOME/vim')
730 let g:yankring_replace_n_pkey = ''
731 let g:yankring_replace_n_nkey = ''
732
733 " map Y to y$ for the yank ring
734 function! YRRunAfterMaps()
735 nnoremap Y :<C-U>YRYankCount 'y$'<CR>
736 endfunction
737
738 " youcompleteme {{{2
739 let g:ycm_extra_conf_globlist = ['~/src/*','/mnt/data/src/*']
740 " ycm-clangd requires you to symlink the compile_db to the root of the project
741 " let g:ycm_global_ycm_extra_conf = expand('$XDG_CONFIG_HOME/vim/ycm_extra_conf.py')
742 let g:ycm_clangd_binary_path = 'clangd' " use clangd in path
743 let g:ycm_extra_conf_vim_data = ['getcwd()']
744 let g:ycm_add_preview_to_completeopt = 1
745 let g:ycm_complete_in_comments = 1
746 let g:ycm_complete_in_strings = 1
747 let g:ycm_autoclose_preview_window_after_insertion = 0
748
749 " vim-easy-align {{{2
750 " start interactive EasyAlign in visual mode
751 vmap <Enter> <Plug>(EasyAlign)
752 nmap ga <Plug>(EasyAlign)
753
754 " vim-gtest {{{2
755 let g:gtest#highlight_failing_tests = 0
756
757 nnoremap <Leader>tt :GTestRun<CR>
758 nnoremap <Leader>ta :GTestCase *<CR>:GTestName *<CR>:GTestRun<CR>
759 nnoremap <Leader>tu :GTestRunUnderCursor<CR>
760
761 " vim-json {{{2
762 let g:vim_json_syntax_conceal = 0
763
764 " vim-sneak {{{2
765 let g:sneak#streak = 1
766 let g:sneak#target_labels = "aoeuisnthdpylrcgfqjkxzmwvz" " dvorak
767 let g:sneak#use_ic_scs = 1 " follow 'ignorecase' and 'smartcase'
768
769 " sneaky f and t
770 nmap f <Plug>Sneak_f
771 nmap F <Plug>Sneak_F
772 xmap f <Plug>Sneak_f
773 xmap F <Plug>Sneak_F
774 omap f <Plug>Sneak_f
775 omap F <Plug>Sneak_F
776 nmap t <Plug>Sneak_t
777 nmap T <Plug>Sneak_T
778 xmap t <Plug>Sneak_t
779 xmap T <Plug>Sneak_T
780 omap t <Plug>Sneak_t
781 omap T <Plug>Sneak_T
782
783 " vimviki {{{2
784 let g:vimwiki_list = [{'path': '$XDG_DATA_HOME/vimwiki'}]
785 let g:vimwiki_auto_chdir = 1
786 augroup myvimwiki
787 au! BufRead $XDG_DATA_HOME/vimwiki/index.wiki !git -C "%:p:h" pull -q
788 au! BufRead,BufNewFile $XDG_DATA_HOME/vimwiki/diary/*.wiki !git -C "%:p:h" pull -q
789 au! BufWritePost $XDG_DATA_HOME/vimwiki/*.wiki exe '!git add "<afile>";git commit -qm"' . strftime("%FT%R") . '";git push -q'
790 augroup END
791
792 " functions {{{1
793
794 " Convenient command to see the difference between the current buffer and the
795 " file it was loaded from, thus the changes you made.
796 " Only define it when not defined already.
797 if !exists(":DiffOrig")
798 command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
799 \ | wincmd p | diffthis
800 endif
801
802 " sort operator {{{2
803 function! SortLinesOpFunc(...)
804 '[,']sort
805 endfunction
806 nnoremap <silent> gs :<C-U>set operatorfunc=SortLinesOpFunc<CR>g@
807 vnoremap <silent> gs :sort<cr>
808
809 " edit configs {{{2
810 function! EditConfig(what, ext = '.vim')
811 let l:dir = split(&runtimepath,',')[0]
812 if a:what == 'vimrc'
813 let l:file = expand($MYVIMRC)
814 elseif ! isdirectory(globpath(l:dir, a:what))
815 echoe a:what." is not valid!"
816 elseif empty(&filetype)
817 echoe 'filetype is empty!'
818 else
819 let l:file = l:dir.'/'.a:what.'/'.&filetype.a:ext
820 endif
821
822 execute ':vsplit '.file
823 execute ':lcd %:p:h'
824 endf
825 nmap <leader>ev :call EditConfig('vimrc')<CR>
826 nmap <leader>ef :call EditConfig('ftplugin')<CR>
827 nmap <leader>es :call EditConfig('syntax')<CR>
828 nmap <leader>ei :call EditConfig('indent')<CR>
829 nmap <leader>eu :call EditConfig('ultisnips', '.snippets')<CR>
830
831 " spell check {{{2
832 " http://tex.stackexchange.com/a/52932
833 let g:myLangList=["en_gb","en_us","de","fr"]
834
835 function! ToggleSpell()
836 if !exists("b:myLang")
837 let b:myLang=0
838 endif
839 execute "setlocal spell!"
840 if (&spell)
841 echo "setlocal spelllang=" g:myLangList[b:myLang]
842 endif
843 endfunction
844
845 function! SwitchSpell()
846 if !exists("b:myLang")
847 let b:myLang=0
848 endif
849 if (&spell)
850 let b:myLang=b:myLang+1
851 if b:myLang>=len(g:myLangList) | let b:myLang=0 | endif
852 endif
853 execute "setlocal spell spelllang=".get(g:myLangList, b:myLang)
854 echo "setlocal spelllang=" g:myLangList[b:myLang]
855 endfunction
856
857 nnoremap <silent> coS :call SwitchSpell()<CR>
858 " fix spelling with first choice
859 nnoremap <Leader>f 1z=
860
861 " gitdir or home {{{2
862 " from derek wyatt:
863 " http://git.io/v3GAV
864 function! FindGitDirOrHome()
865 let filedir = expand('%:p:h')
866 if isdirectory(filedir)
867 let cmd = 'bash -c "(cd ' . filedir . '; git rev-parse --show-toplevel 2>/dev/null)"'
868 let gitdir = system(cmd)
869 if strlen(gitdir) == 0
870 return '~'
871 else
872 return gitdir[:-2]
873 endif
874 else
875 return '~'
876 endif
877 endfunction
878 command! Cd cd %:h
879 command! Cdr execute('cd ' . FindGitDirOrHome())
880 command! LCd lcd %:h
881 command! LCdr execute('lcd ' . FindGitDirOrHome())
882
883 " vim:set et sw=2 ts=2 tw=78: