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