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