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