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