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