comparison .chezmoitemplates/config.vim @ 460:ae7e377bced8

Add autocmd wrapper for lua
author zegervdv <zegervdv@me.com>
date Sun, 19 Sep 2021 14:57:14 +0200
parents d99353d71702
children 1d2e33dfe0c6
comparison
equal deleted inserted replaced
459:43262db8ecf6 460:ae7e377bced8
1 " vim:fdm=marker:ts=2:sw=2 1 " vim:fdm=marker:ts=2:sw=2
2 2
3 let s:darwin = has('mac') 3 let s:darwin = has('mac')
4 let s:windows = has('win32') 4 let s:windows = has('win32')
5 5
6 " Activate built in plugins 6 " Activate built in plugins
7 if !has('nvim') 7 if !has('nvim')
8 if has('packages') 8 if has('packages')
9 packadd! matchit 9 packadd! matchit
10 packadd! shellmenu 10 packadd! shellmenu
11 endif 11 endif
19 19
20 if has("nvim") 20 if has("nvim")
21 let g:python3_host_prog=expand('$HOME/.config/virtualenvs/python3/bin/python') 21 let g:python3_host_prog=expand('$HOME/.config/virtualenvs/python3/bin/python')
22 let g:python_host_prog=expand('$HOME/.config/virtualenvs/python2/bin/python') 22 let g:python_host_prog=expand('$HOME/.config/virtualenvs/python2/bin/python')
23 endif 23 endif
24 " 24 "
25 25
26 " General Settings and options 26 " General Settings and options
27 27
28 augroup cline 28 augroup cline
29 au! 29 au!
30 autocmd WinEnter * setlocal cursorline 30 autocmd WinEnter * setlocal cursorline
31 autocmd WinLeave * setlocal nocursorline 31 autocmd WinLeave * setlocal nocursorline
44 if !isdirectory(expand(&undodir)) 44 if !isdirectory(expand(&undodir))
45 call mkdir(expand(&undodir), "p") 45 call mkdir(expand(&undodir), "p")
46 endif 46 endif
47 endif 47 endif
48 48
49 " 49 "
50 50
51 " Mappings 51 " Mappings
52 " Set leader to spacebar 52 " Set leader to spacebar
53 map <space> <leader> 53 map <space> <leader>
54 54
55 " See long lines as line breaks 55 " See long lines as line breaks
56 noremap <expr> j (v:count? 'j' : 'gj') 56 noremap <expr> j (v:count? 'j' : 'gj')
189 nnoremap <leader>b :vert sbuffer 189 nnoremap <leader>b :vert sbuffer
190 nnoremap <leader>t :vert stjump 190 nnoremap <leader>t :vert stjump
191 nnoremap <leader>f :vert sfind 191 nnoremap <leader>f :vert sfind
192 192
193 193
194 " 194 "
195 195
196 " Functions 196 " Functions
197 " When editing a file, always jump to the last known cursor position. 197 " When editing a file, always jump to the last known cursor position.
198 " Don't do it for commit messages, when the position is invalid, or when 198 " Don't do it for commit messages, when the position is invalid, or when
199 " inside an event handler (happens when dropping a file on gvim). 199 " inside an event handler (happens when dropping a file on gvim).
200 autocmd BufReadPost * 200 autocmd BufReadPost *
201 \ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") | 201 \ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") |
217 augroup focus_lost 217 augroup focus_lost
218 au! 218 au!
219 au FocusLost * if !&readonly | :wa | endif 219 au FocusLost * if !&readonly | :wa | endif
220 augroup END 220 augroup END
221 221
222 augroup LuaHighlight 222 " Resize splits after window resize
223 autocmd!
224 autocmd TextYankPost * silent! lua require'vim.highlight'.on_yank()
225 augroup END
226
227 " Resize splits after window resize
228 augroup vim_resize 223 augroup vim_resize
229 au! 224 au!
230 au VimResized * exe "normal! \<c-w>=" 225 au VimResized * exe "normal! \<c-w>="
231 augroup END 226 augroup END
232 " 227 "
233 228
234 " Automatically reload vimrc when saving 229 " Automatically reload vimrc when saving
235 augroup reload_vim 230 augroup reload_vim
236 autocmd! 231 autocmd!
237 autocmd BufWritePost $MYVIMRC nested source $MYVIMRC 232 autocmd BufWritePost $MYVIMRC nested source $MYVIMRC
238 augroup END 233 augroup END
239 " 234 "
240 235
241 " Reload diffs 236 " Reload diffs
242 augroup diff_files 237 augroup diff_files
243 au! 238 au!
244 au BufWritePost * if &diff == 1 | diffupdate | endif 239 au BufWritePost * if &diff == 1 | diffupdate | endif
245 augroup END 240 augroup END
246 " 241 "
247 242
248 " Custom folding by Steve Losh 243 " Custom folding by Steve Losh
249 function! MyFoldText() " 244 function! MyFoldText() "
250 let line = getline(v:foldstart) 245 let line = getline(v:foldstart)
251 246
252 let nucolwidth = &fdc + &number * &numberwidth 247 let nucolwidth = &fdc + &number * &numberwidth
253 let windowwidth = winwidth(0) - nucolwidth - 3 248 let windowwidth = winwidth(0) - nucolwidth - 3
254 let foldedlinecount = v:foldend - v:foldstart 249 let foldedlinecount = v:foldend - v:foldstart
258 let line = substitute(line, '\t', onetab, 'g') 253 let line = substitute(line, '\t', onetab, 'g')
259 254
260 let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount)) 255 let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
261 let fillcharcount = windowwidth - len(line) - len(foldedlinecount) 256 let fillcharcount = windowwidth - len(line) - len(foldedlinecount)
262 return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' ' 257 return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' '
263 endfunction " 258 endfunction "
264 set foldtext=MyFoldText() 259 set foldtext=MyFoldText()
265 set foldopen+=jump 260 set foldopen+=jump
266 261
267 " Detect Filetype from content if file has no extension 262 " Detect Filetype from content if file has no extension
268 augroup newFileDetection 263 augroup newFileDetection
269 au! 264 au!
270 autocmd CursorMovedI * call CheckFileType() 265 autocmd CursorMovedI * call CheckFileType()
271 augroup END 266 augroup END
272 267
281 " been found 276 " been found
282 elseif b:countCheck >= 200 || &filetype != "" 277 elseif b:countCheck >= 200 || &filetype != ""
283 autocmd! newFileDetection 278 autocmd! newFileDetection
284 endif 279 endif
285 endfunction 280 endfunction
286 " 281 "
287 282
288 " Convert hex <-> decimal 283 " Convert hex <-> decimal
289 command! -nargs=? -range Dec2hex call s:Dec2hex(<line1>, <line2>, '<args>') 284 command! -nargs=? -range Dec2hex call s:Dec2hex(<line1>, <line2>, '<args>')
290 function! s:Dec2hex(line1, line2, arg) range 285 function! s:Dec2hex(line1, line2, arg) range
291 if empty(a:arg) 286 if empty(a:arg)
292 if histget(':', -1) =~# "^'<,'>" && visualmode() !=# 'V' 287 if histget(':', -1) =~# "^'<,'>" && visualmode() !=# 'V'
293 let cmd = 's/\%V\<\d\+\>/\=printf("0x%x",submatch(0)+0)/g' 288 let cmd = 's/\%V\<\d\+\>/\=printf("0x%x",submatch(0)+0)/g'
319 endtry 314 endtry
320 else 315 else
321 echo (a:arg =~? '^0x') ? a:arg + 0 : ('0x'.a:arg) + 0 316 echo (a:arg =~? '^0x') ? a:arg + 0 : ('0x'.a:arg) + 0
322 endif 317 endif
323 endfunction 318 endfunction
324 " 319 "
325 320
326 " Recognize filetype for dup files 321 " Recognize filetype for dup files
327 autocmd! BufRead *.dup call DupSetSyntax(@%) 322 autocmd! BufRead *.dup call DupSetSyntax(@%)
328 323
329 function! DupSetSyntax(name) 324 function! DupSetSyntax(name)
330 let extension = matchlist(a:name, '\v.+.\.([^\.]+).dup')[1] 325 let extension = matchlist(a:name, '\v.+.\.([^\.]+).dup')[1]
331 if extension == "vhd" 326 if extension == "vhd"
336 setlocal filetype=verilog 331 setlocal filetype=verilog
337 else 332 else
338 echo "Unknown filetype" 333 echo "Unknown filetype"
339 endif 334 endif
340 endfunction 335 endfunction
341 " 336 "
342 337
343 " Create arguments list from files in quickfix list 338 " Create arguments list from files in quickfix list
344 " Allows to Grep for a pattern and apply an argdo command on each of the 339 " Allows to Grep for a pattern and apply an argdo command on each of the
345 " matching files 340 " matching files
346 command! -nargs=0 -bar Qargs execute 'args' QuickfixFilenames() 341 command! -nargs=0 -bar Qargs execute 'args' QuickfixFilenames()
347 function! QuickfixFilenames() 342 function! QuickfixFilenames()
348 " Building a hash ensures we get each buffer only once 343 " Building a hash ensures we get each buffer only once
349 let buffer_numbers = {} 344 let buffer_numbers = {}
350 for quickfix_item in getqflist() 345 for quickfix_item in getqflist()
361 au BufLeave drv_*.tcl mark D 356 au BufLeave drv_*.tcl mark D
362 au BufLeave *.rtl.vhd mark R 357 au BufLeave *.rtl.vhd mark R
363 augroup END 358 augroup END
364 359
365 360
366 " Toggle between opening/closing the quickfix window 361 " Toggle between opening/closing the quickfix window
367 function! GetBufferList() 362 function! GetBufferList()
368 redir =>buflist 363 redir =>buflist
369 silent! ls! 364 silent! ls!
370 redir END 365 redir END
371 return buflist 366 return buflist
390 wincmd p 385 wincmd p
391 endif 386 endif
392 endfunction 387 endfunction
393 388
394 nnoremap <silent> <F10> :call ToggleList("Quickfix List", 'c')<CR> 389 nnoremap <silent> <F10> :call ToggleList("Quickfix List", 'c')<CR>
395 " 390 "
396 391
397 392
398 " Make list-like commands more intuitive 393 " Make list-like commands more intuitive
399 " Copied from https://gist.github.com/romainl/047aca21e338df7ccf771f96858edb86 394 " Copied from https://gist.github.com/romainl/047aca21e338df7ccf771f96858edb86
400 function! CCR() 395 function! CCR()
401 let cmdline = getcmdline() 396 let cmdline = getcmdline()
402 if cmdline =~ '\v\C^(ls|files|buffers)' 397 if cmdline =~ '\v\C^(ls|files|buffers)'
403 " like :ls but prompts for a buffer command 398 " like :ls but prompts for a buffer command
432 else 427 else
433 return "\<CR>" 428 return "\<CR>"
434 endif 429 endif
435 endfunction 430 endfunction
436 cnoremap <expr> <CR> CCR() 431 cnoremap <expr> <CR> CCR()
437 " 432 "
438 433
439 " Text objects 434 " Text objects
440 function! s:inIndentation() 435 function! s:inIndentation()
441 " select all text in current indentation level excluding any empty lines 436 " select all text in current indentation level excluding any empty lines
442 " that precede or follow the current indentationt level; 437 " that precede or follow the current indentationt level;
443 " 438 "
444 " the current implementation is pretty fast, even for many lines since it 439 " the current implementation is pretty fast, even for many lines since it
566 endfunction 561 endfunction
567 562
568 " "around indentation" (indentation level and any surrounding empty lines) 563 " "around indentation" (indentation level and any surrounding empty lines)
569 xnoremap <silent> ai :<c-u>call <sid>aroundIndentation()<cr> 564 xnoremap <silent> ai :<c-u>call <sid>aroundIndentation()<cr>
570 onoremap <silent> ai :<c-u>call <sid>aroundIndentation()<cr> 565 onoremap <silent> ai :<c-u>call <sid>aroundIndentation()<cr>
571 " 566 "
572 " 567 "
573 568
574 " Filetype specific settings 569 " Filetype specific settings
575 " Text 570 " Text
576 augroup ft_text 571 augroup ft_text
577 au! 572 au!
578 " au BufNewFile,BufRead,BufEnter *.txt setlocal spell spelllang=en_gb 573 " au BufNewFile,BufRead,BufEnter *.txt setlocal spell spelllang=en_gb
579 au BufNewFile,BufRead,BufEnter *.txt setlocal textwidth=0 574 au BufNewFile,BufRead,BufEnter *.txt setlocal textwidth=0
580 augroup END 575 augroup END
592 syn match Statement "\v<\d{7,9}>" 587 syn match Statement "\v<\d{7,9}>"
593 588
594 " Color errors 589 " Color errors
595 syn match Error "\v^ERROR:.*$" 590 syn match Error "\v^ERROR:.*$"
596 endfunction 591 endfunction
597 " 592 "
598 " Git commit messages 593 " Git commit messages
599 augroup ft_git 594 augroup ft_git
600 au! 595 au!
601 au FileType gitcommit setlocal spell spelllang=en_gb 596 au FileType gitcommit setlocal spell spelllang=en_gb
602 autocmd FileType gitcommit,gitrebase,gitconfig set bufhidden=delete 597 autocmd FileType gitcommit,gitrebase,gitconfig set bufhidden=delete
603 augroup END 598 augroup END
604 " 599 "
605 " Ruby 600 " Ruby
606 augroup ft_ruby 601 augroup ft_ruby
607 au! 602 au!
608 autocmd BufRead *_spec.rb set filetype=rspec 603 autocmd BufRead *_spec.rb set filetype=rspec
609 augroup END 604 augroup END
610 " 605 "
611 " Matlab 606 " Matlab
612 augroup ft_matlab 607 augroup ft_matlab
613 au! 608 au!
614 autocmd FileType matlab setlocal commentstring=\%\ %s 609 autocmd FileType matlab setlocal commentstring=\%\ %s
615 augroup END 610 augroup END
616 " 611 "
617 " C 612 " C
618 augroup ft_c 613 augroup ft_c
619 au! 614 au!
620 au FileType c setlocal foldmethod=syntax 615 au FileType c setlocal foldmethod=syntax
621 augroup END 616 augroup END
622 " 617 "
623 " TCL 618 " TCL
624 619
625 augroup ft_tcl 620 augroup ft_tcl
626 au! 621 au!
627 autocmd FileType tcl setlocal commentstring=#\ %s 622 autocmd FileType tcl setlocal commentstring=#\ %s
628 " autocmd FileType tcl compiler nagelfar 623 " autocmd FileType tcl compiler nagelfar
632 autocmd FileType tcl setlocal breakat-=: 627 autocmd FileType tcl setlocal breakat-=:
633 autocmd FileType tcl setlocal suffixesadd+=.tcl,.do 628 autocmd FileType tcl setlocal suffixesadd+=.tcl,.do
634 augroup END 629 augroup END
635 " shortcuts 630 " shortcuts
636 iabbrev procargs array set arg [::argument_processing::proces_arguments $args]; 631 iabbrev procargs array set arg [::argument_processing::proces_arguments $args];
637 " 632 "
638 " GPG 633 " GPG
639 " Don't save backups of gpg asc files 634 " Don't save backups of gpg asc files
640 set backupskip+=*.asc 635 set backupskip+=*.asc
641 636
642 " Convenient editing of ascii-armoured encrypted files 637 " Convenient editing of ascii-armoured encrypted files
643 augroup GPGASCII 638 augroup GPGASCII
646 au BufReadPost *.asc |redraw 641 au BufReadPost *.asc |redraw
647 au BufWritePre *.asc :%!gpg -q -e -a 642 au BufWritePre *.asc :%!gpg -q -e -a
648 au BufWritePost *.asc u 643 au BufWritePost *.asc u
649 au VimLeave *.asc :!clear 644 au VimLeave *.asc :!clear
650 augroup END 645 augroup END
651 " 646 "
652 " System Verilog 647 " System Verilog
653 augroup ft_systemverilog 648 augroup ft_systemverilog
654 au! 649 au!
655 au FileType systemverilog setlocal suffixesadd+=.sv,.v 650 au FileType systemverilog setlocal suffixesadd+=.sv,.v
656 au FileType systemverilog setlocal foldmethod=expr 651 au FileType systemverilog setlocal foldmethod=expr
657 au FileType systemverilog setlocal foldexpr=nvim_treesitter#foldexpr() 652 au FileType systemverilog setlocal foldexpr=nvim_treesitter#foldexpr()
663 function! SVAlign() 658 function! SVAlign()
664 let g:easy_align_delimiters = { 659 let g:easy_align_delimiters = {
665 \ ')': { 'pattern': '[()]', 'left_margin': 0, 'right_margin': 0, 'stick_to_left': 0} 660 \ ')': { 'pattern': '[()]', 'left_margin': 0, 'right_margin': 0, 'stick_to_left': 0}
666 \} 661 \}
667 endfunction 662 endfunction
668 " 663 "
669 " Make 664 " Make
670 augroup ft_make 665 augroup ft_make
671 autocmd! 666 autocmd!
672 autocmd BufEnter *.make setlocal filetype=make 667 autocmd BufEnter *.make setlocal filetype=make
673 autocmd FileType make setlocal noexpandtab 668 autocmd FileType make setlocal noexpandtab
674 augroup END 669 augroup END
675 " JSON 670 " JSON
676 augroup ft_json 671 augroup ft_json
677 autocmd! 672 autocmd!
678 autocmd FileType json setlocal equalprg=jq 673 autocmd FileType json setlocal equalprg=jq
679 augroup END 674 augroup END
680 " 675 "
681 " 676 "
682 " Python 677 " Python
683 augroup f_python 678 augroup f_python
684 autocmd! 679 autocmd!
685 autocmd FileType python setlocal shiftwidth=4 680 autocmd FileType python setlocal shiftwidth=4
686 au FileType python setlocal formatprg=autopep8\ - 681 au FileType python setlocal formatprg=autopep8\ -
687 autocmd FileType python setlocal path-=** 682 autocmd FileType python setlocal path-=**
688 autocmd Filetype python let b:delimitMate_nesting_quotes = ['"', "'"] 683 autocmd Filetype python let b:delimitMate_nesting_quotes = ['"', "'"]
689 augroup END 684 augroup END
690 685
691 let g:python_highlight_all=1 686 let g:python_highlight_all=1
692 " 687 "
693 " 688 "
694 689
695 " Plugin settings 690 " Plugin settings
696 " Gundo tree 691 " Gundo tree
697 nnoremap <leader>u :GundoToggle<CR> 692 nnoremap <leader>u :GundoToggle<CR>
698 " 693 "
699 " Projectionist 694 " Projectionist
700 let g:projectionist_heuristics = { 695 let g:projectionist_heuristics = {
701 \ "*.c": { 696 \ "*.c": {
702 \ "*.c": { 697 \ "*.c": {
703 \ "alternate": "{}.h", 698 \ "alternate": "{}.h",
704 \ "type": "source", 699 \ "type": "source",
714 \ }, 709 \ },
715 \ "*.py": { 710 \ "*.py": {
716 \ "*.py": { "make": "ipython {}" } 711 \ "*.py": { "make": "ipython {}" }
717 \ }, 712 \ },
718 \ } 713 \ }
719 " 714 "
720 " Grep 715 " Grep
721 let g:grepper = { 716 let g:grepper = {
722 \ 'tools': ['ag', 'hg'], 717 \ 'tools': ['ag', 'hg'],
723 \ 'highlight': 1, 718 \ 'highlight': 1,
724 \ 'ag': { 719 \ 'ag': {
725 \ 'grepprg': 'rg --vimgrep', 720 \ 'grepprg': 'rg --vimgrep',
728 nnoremap gs <plug>(GrepperOperator) 723 nnoremap gs <plug>(GrepperOperator)
729 xnoremap gs <plug>(GrepperOperator) 724 xnoremap gs <plug>(GrepperOperator)
730 725
731 726
732 command! -nargs=* -complete=file Ag Grepper -noprompt -tool ag -grepprg rg --vimgrep <args> 727 command! -nargs=* -complete=file Ag Grepper -noprompt -tool ag -grepprg rg --vimgrep <args>
733 " 728 "
734 " Vinegar/NetRW 729 " Vinegar/NetRW
735 autocmd FileType netrw setl bufhidden=delete 730 autocmd FileType netrw setl bufhidden=delete
736 " 731 "
737 " NCM 732 " NCM
738 function! s:check_back_space() abort 733 function! s:check_back_space() abort
739 let col = col('.') - 1 734 let col = col('.') - 1
740 return !col || getline('.')[col - 1] =~# '\s' 735 return !col || getline('.')[col - 1] =~# '\s'
741 endfunction 736 endfunction
742 737
761 imap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>' 756 imap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'
762 smap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>' 757 smap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>'
763 imap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>' 758 imap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>'
764 smap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>' 759 smap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>'
765 760
766 " 761 "
767 " 762 "
768 " 763 "
769 764
770 function! SendOSCClipboard(lines, regtype) 765 function! SendOSCClipboard(lines, regtype)
771 call SendViaOSC52(join(a:lines, "\n")) 766 call SendViaOSC52(join(a:lines, "\n"))
772 endfunction 767 endfunction
773 768