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