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