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