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