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