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