Mercurial > dotfiles
annotate dot_config/nvim/plugin/config.vim @ 425:10916f9b1676
Replace delimitMate with nvim-autopairs
author | zegervdv <zegervdv@me.com> |
---|---|
date | Wed, 28 Jul 2021 11:42:54 +0200 |
parents | 5683e8e3e361 |
children | 5a296952f248 |
rev | line source |
---|---|
411 | 1 " vim:fdm=marker:ts=2:sw=2 |
2 | |
3 let s:darwin = has('mac') | |
4 let s:windows = has('win32') | |
5 | |
6 " Activate built in plugins {{{ | |
7 if !has('nvim') | |
8 if has('packages') | |
9 packadd! matchit | |
10 packadd! shellmenu | |
11 endif | |
12 endif | |
13 source $VIMRUNTIME/ftplugin/man.vim | |
14 | |
15 if has('packages') | |
16 silent! packadd! log_file | |
17 silent! packadd! snippets | |
18 endif | |
19 | |
20 if has("nvim") | |
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') | |
23 endif | |
24 " }}} | |
25 | |
26 " General Settings and options {{{ | |
27 | |
28 augroup cline | |
29 au! | |
30 autocmd WinEnter * setlocal cursorline | |
31 autocmd WinLeave * setlocal nocursorline | |
32 augroup END | |
33 | |
34 if !isdirectory(expand(&backupdir)) | |
35 call mkdir(expand(&backupdir), "p") | |
36 endif | |
37 if !isdirectory(expand(&directory)) | |
38 call mkdir(expand(&directory), "p") | |
39 endif | |
40 | |
41 if v:version >= 703 | |
42 if !isdirectory(expand(&undodir)) | |
43 call mkdir(expand(&undodir), "p") | |
44 endif | |
45 endif | |
46 | |
47 " }}} | |
48 | |
49 " Mappings {{{ | |
50 " Set leader to spacebar | |
51 map <space> <leader> | |
52 | |
53 " See long lines as line breaks | |
54 noremap <expr> j (v:count? 'j' : 'gj') | |
55 noremap <expr> k (v:count? 'k' : 'gk') | |
56 | |
57 " Remap tag-search to better place | |
58 nnoremap <C-$> g<C-]> | |
59 nnoremap <C-w>y <C-w>g<C-]> | |
60 | |
61 nnoremap <C-s> <C-e> | |
62 | |
63 " Move while in insert mode | |
64 inoremap <C-f> <right> | |
65 | |
66 " Switch between the last two files | |
67 " nnoremap <space><space> <C-^> | |
68 | |
69 " " Very Magic search patterns | |
70 nnoremap / /\v | |
71 vnoremap / /\v | |
72 | |
73 " Keep search matches in the middle of the window. | |
74 nnoremap n nzzzv | |
75 nnoremap N Nzzzv | |
76 | |
77 " Search for beginning of command | |
78 cnoremap <c-n> <down> | |
79 cnoremap <c-p> <up> | |
80 | |
81 " Move whole lines | |
82 nnoremap [e :<c-u>execute 'move -1-'. v:count1<cr> | |
83 nnoremap ]e :<c-u>execute 'move +'. v:count1<cr> | |
84 | |
85 " Insert empty lines | |
86 nnoremap [<space> :<c-u>put! =repeat(nr2char(10), v:count1)<cr>'[ | |
87 nnoremap ]<space> :<c-u>put =repeat(nr2char(10), v:count1)<cr> | |
88 | |
89 " Clear highlight | |
90 nnoremap <silent><leader>l :noh<CR> | |
91 | |
92 inoremap £ \ | |
93 | |
94 " Highlight last inserted text | |
95 nnoremap gV `[v`] | |
96 | |
97 " Highlight VCS conflict markers | |
98 match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$' | |
99 | |
100 " Use backspace as delete in visual mode | |
101 vmap <BS> x | |
102 | |
103 " Redraw screen | |
104 nnoremap <F3> :redraw!<CR> | |
105 | |
106 " Keep selection when shifting | |
107 vmap <expr> > KeepVisualSelection(">") | |
108 vmap <expr> < KeepVisualSelection("<") | |
109 | |
110 function! KeepVisualSelection(cmd) | |
111 set nosmartindent | |
112 if mode() ==# "V" | |
113 return a:cmd . ":set smartindent\<CR>gv" | |
114 else | |
115 return a:cmd . ":set smartindent\<CR>" | |
116 endif | |
117 endfunction | |
118 | |
119 " Swap backticks and quotes | |
120 nnoremap ` ' | |
121 nnoremap ' ` | |
122 | |
123 " Open vimrc | |
124 nnoremap <leader>ve :e $MYVIMRC<CR> | |
125 nnoremap <leader>vs :so $MYVIMRC<CR> | |
126 | |
127 " Open dup in diffmode | |
128 nnoremap <leader>d :call OpenDup(@%)<CR> | |
129 | |
130 function! OpenDup(file) | |
131 let l:filename = a:file . ".dup" | |
132 execute 'vsplit' l:filename | |
133 windo diffthis | |
134 endfunction | |
135 | |
136 " Do not move on * | |
137 nnoremap <silent> * :let stay_star_view = winsaveview()<cr>*:call winrestview(stay_star_view)<cr> | |
138 | |
139 " Search for selected text, forwards or backwards. | |
140 vnoremap <silent> * :<C-U> | |
141 \let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR> | |
142 \gvy/<C-R><C-R>=substitute( | |
143 \escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR> | |
144 \gV:call setreg('"', old_reg, old_regtype)<CR> | |
145 vnoremap <silent> # :<C-U> | |
146 \let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR> | |
147 \gvy?<C-R><C-R>=substitute( | |
148 \escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR> | |
149 \gV:call setreg('"', old_reg, old_regtype)<CR> | |
150 | |
151 " nnoremap <F10> :botright copen<CR> | |
152 | |
153 xnoremap <silent> p p:if v:register == '"'<Bar>let @@=@0<Bar>endif<CR> | |
154 | |
155 " Error navigation | |
156 nnoremap <UP> :cprev<CR> | |
157 nnoremap <DOWN> :cnext<CR> | |
158 nnoremap <RIGHT> :cnf<CR> | |
159 nnoremap <LEFT> :cpf<CR> | |
160 | |
161 nnoremap <leader>y :ptjump <c-r><c-w><CR> | |
162 | |
163 function! ToggleDiff() | |
164 if &diff == 1 | |
165 windo diffoff | |
166 else | |
167 windo diffthis | |
168 endif | |
169 endfunction | |
170 nnoremap <leader>g :call ToggleDiff()<CR> | |
171 | |
172 if has('nvim') | |
173 tnoremap <C-h> <C-\><C-n><C-w>h | |
174 tnoremap <C-j> <C-\><C-n><C-w>j | |
175 tnoremap <C-k> <C-\><C-n><C-w>k | |
176 tnoremap <C-l> <C-\><C-n><C-w>l | |
177 augroup enter_term | |
178 au! | |
179 autocmd TermOpen * startinsert! | |
180 autocmd BufEnter * if &buftype ==# 'terminal' | :startinsert! | endif | |
181 autocmd BufLeave * if &buftype ==# 'terminal' | :stopinsert! | endif | |
182 augroup END | |
183 let $GIT_EDITOR = 'nvr -cc split --remote-wait' | |
184 endif | |
185 | |
186 " Open buffers, tags... in vertical splits | |
423 | 187 nnoremap <leader>b :vert sbuffer |
188 nnoremap <leader>t :vert stjump | |
189 nnoremap <leader>f :vert sfind | |
411 | 190 |
191 | |
192 " }}} | |
193 | |
194 " Functions {{{ | |
195 " When editing a file, always jump to the last known cursor position. | |
196 " Don't do it for commit messages, when the position is invalid, or when | |
197 " inside an event handler (happens when dropping a file on gvim). | |
198 autocmd BufReadPost * | |
199 \ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") | | |
200 \ exe "normal g`\"" | | |
201 \ endif | |
202 | |
203 " Thg mappings | |
204 function! s:HGhist(file) | |
205 if !empty(a:file) | |
206 let path = a:file | |
207 else | |
208 let path = expand('%') | |
209 endif | |
210 exec 'silent! !thg filelog ' . path . ' &' | |
211 endfunction | |
212 | |
213 command! -nargs=? -complete=file HGhist call s:HGhist(<q-args>) | |
214 | |
215 augroup focus_lost | |
216 au! | |
217 au FocusLost * if !&readonly | :wa | endif | |
218 augroup END | |
219 | |
220 augroup LuaHighlight | |
221 autocmd! | |
222 autocmd TextYankPost * silent! lua require'vim.highlight'.on_yank() | |
223 augroup END | |
224 | |
225 " Resize splits after window resize {{{ | |
226 augroup vim_resize | |
227 au! | |
228 au VimResized * exe "normal! \<c-w>=" | |
229 augroup END | |
230 " }}} | |
231 | |
232 " Automatically reload vimrc when saving {{{ | |
233 augroup reload_vim | |
234 autocmd! | |
235 autocmd BufWritePost $MYVIMRC nested source $MYVIMRC | |
236 augroup END | |
237 " }}} | |
238 | |
239 " Reload diffs {{{ | |
240 augroup diff_files | |
241 au! | |
242 au BufWritePost * if &diff == 1 | diffupdate | endif | |
243 augroup END | |
244 " }}} | |
245 | |
246 " Custom folding by Steve Losh | |
247 function! MyFoldText() " {{{ | |
248 let line = getline(v:foldstart) | |
249 | |
250 let nucolwidth = &fdc + &number * &numberwidth | |
251 let windowwidth = winwidth(0) - nucolwidth - 3 | |
252 let foldedlinecount = v:foldend - v:foldstart | |
253 | |
254 " expand tabs into spaces | |
255 let onetab = strpart(' ', 0, &tabstop) | |
256 let line = substitute(line, '\t', onetab, 'g') | |
257 | |
258 let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount)) | |
259 let fillcharcount = windowwidth - len(line) - len(foldedlinecount) | |
260 return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' ' | |
261 endfunction " }}} | |
262 set foldtext=MyFoldText() | |
263 set foldopen+=jump | |
264 | |
265 " Detect Filetype from content if file has no extension {{{ | |
266 augroup newFileDetection | |
267 au! | |
268 autocmd CursorMovedI * call CheckFileType() | |
269 augroup END | |
270 | |
271 function! CheckFileType() | |
272 if exists("b:countCheck") == 0 | |
273 let b:countCheck = 0 | |
274 endif | |
275 let b:countCheck += 1 | |
276 if &filetype == "" && b:countCheck > 20 && b:countCheck < 200 | |
277 filetype detect | |
278 " Delete the function if no filetype can be established, or the type has | |
279 " been found | |
280 elseif b:countCheck >= 200 || &filetype != "" | |
281 autocmd! newFileDetection | |
282 endif | |
283 endfunction | |
284 " }}} | |
285 | |
286 " Convert hex <-> decimal {{{ | |
287 command! -nargs=? -range Dec2hex call s:Dec2hex(<line1>, <line2>, '<args>') | |
288 function! s:Dec2hex(line1, line2, arg) range | |
289 if empty(a:arg) | |
290 if histget(':', -1) =~# "^'<,'>" && visualmode() !=# 'V' | |
291 let cmd = 's/\%V\<\d\+\>/\=printf("0x%x",submatch(0)+0)/g' | |
292 else | |
293 let cmd = 's/\<\d\+\>/\=printf("0x%x",submatch(0)+0)/g' | |
294 endif | |
295 try | |
296 execute a:line1 . ',' . a:line2 . cmd | |
297 catch | |
298 echo 'Error: No decimal number found' | |
299 endtry | |
300 else | |
301 echo printf('%x', a:arg + 0) | |
302 endif | |
303 endfunction | |
304 | |
305 command! -nargs=? -range Hex2dec call s:Hex2dec(<line1>, <line2>, '<args>') | |
306 function! s:Hex2dec(line1, line2, arg) range | |
307 if empty(a:arg) | |
308 if histget(':', -1) =~# "^'<,'>" && visualmode() !=# 'V' | |
309 let cmd = 's/\%V0x\x\+/\=submatch(0)+0/g' | |
310 else | |
311 let cmd = 's/0x\x\+/\=submatch(0)+0/g' | |
312 endif | |
313 try | |
314 execute a:line1 . ',' . a:line2 . cmd | |
315 catch | |
316 echo 'Error: No hex number starting "0x" found' | |
317 endtry | |
318 else | |
319 echo (a:arg =~? '^0x') ? a:arg + 0 : ('0x'.a:arg) + 0 | |
320 endif | |
321 endfunction | |
322 " }}} | |
323 | |
324 " Recognize filetype for dup files {{{ | |
325 autocmd! BufRead *.dup call DupSetSyntax(@%) | |
326 | |
327 function! DupSetSyntax(name) | |
328 let extension = matchlist(a:name, '\v.+.\.([^\.]+).dup')[1] | |
329 if extension == "vhd" | |
330 setlocal filetype=vhdl | |
331 elseif extension == "v" | |
332 setlocal filetype=verilog | |
333 elseif extension == "sv" | |
334 setlocal filetype=verilog | |
335 else | |
336 echo "Unknown filetype" | |
337 endif | |
338 endfunction | |
339 " }}} | |
340 | |
341 " Create arguments list from files in quickfix list | |
342 " Allows to Grep for a pattern and apply an argdo command on each of the | |
343 " matching files {{{ | |
344 command! -nargs=0 -bar Qargs execute 'args' QuickfixFilenames() | |
345 function! QuickfixFilenames() | |
346 " Building a hash ensures we get each buffer only once | |
347 let buffer_numbers = {} | |
348 for quickfix_item in getqflist() | |
349 let buffer_numbers[quickfix_item['bufnr']] = bufname(quickfix_item['bufnr']) | |
350 endfor | |
351 return join(map(values(buffer_numbers), 'fnameescape(v:val)')) | |
352 endfunction | |
353 "}}} | |
354 | |
355 augroup mark_files | |
356 au! | |
357 au BufLeave test.tcl mark T | |
358 au BufLeave case.do mark C | |
359 au BufLeave drv_*.tcl mark D | |
360 au BufLeave *.rtl.vhd mark R | |
361 augroup END | |
362 | |
363 | |
364 " Toggle between opening/closing the quickfix window {{{ | |
365 function! GetBufferList() | |
366 redir =>buflist | |
367 silent! ls! | |
368 redir END | |
369 return buflist | |
370 endfunction | |
371 | |
372 function! ToggleList(bufname, pfx) | |
373 let buflist = GetBufferList() | |
374 for bufnum in map(filter(split(buflist, '\n'), 'v:val =~ "'.a:bufname.'"'), 'str2nr(matchstr(v:val, "\\d\\+"))') | |
375 if bufwinnr(bufnum) != -1 | |
376 exec(a:pfx.'close') | |
377 return | |
378 endif | |
379 endfor | |
380 if a:pfx == 'l' && len(getloclist(0)) == 0 | |
381 echohl ErrorMsg | |
382 echo "Location List is Empty." | |
383 return | |
384 endif | |
385 let winnr = winnr() | |
386 exec('botright '.a:pfx.'open') | |
387 if winnr() != winnr | |
388 wincmd p | |
389 endif | |
390 endfunction | |
391 | |
392 nnoremap <silent> <F10> :call ToggleList("Quickfix List", 'c')<CR> | |
393 " }}} | |
394 | |
395 | |
396 " Make list-like commands more intuitive {{{ | |
397 " Copied from https://gist.github.com/romainl/047aca21e338df7ccf771f96858edb86 | |
398 function! CCR() | |
399 let cmdline = getcmdline() | |
400 if cmdline =~ '\v\C^(ls|files|buffers)' | |
401 " like :ls but prompts for a buffer command | |
402 return "\<CR>:b" | |
403 elseif cmdline =~ '\v\C/(#|nu|num|numb|numbe|number)$' | |
404 " like :g//# but prompts for a command | |
405 return "\<CR>:" | |
406 elseif cmdline =~ '\v\C^(dli|il)' | |
407 " like :dlist or :ilist but prompts for a count for :djump or :ijump | |
408 return "\<CR>:" . cmdline[0] . "j " . split(cmdline, " ")[1] . "\<S-Left>\<Left>" | |
409 elseif cmdline =~ '\v\C^(cli|lli)' | |
410 " like :clist or :llist but prompts for an error/location number | |
411 return "\<CR>:sil " . repeat(cmdline[0], 2) . "\<Space>" | |
412 elseif cmdline =~ '\C^old' | |
413 " like :oldfiles but prompts for an old file to edit | |
414 set nomore | |
415 return "\<CR>:sil se more|e #<" | |
416 elseif cmdline =~ '\C^changes' | |
417 " like :changes but prompts for a change to jump to | |
418 set nomore | |
419 return "\<CR>:sil se more|norm! g;\<S-Left>" | |
420 elseif cmdline =~ '\C^ju' | |
421 " like :jumps but prompts for a position to jump to | |
422 set nomore | |
423 return "\<CR>:sil se more|norm! \<C-o>\<S-Left>" | |
424 elseif cmdline =~ '\C^marks' | |
425 " like :marks but prompts for a mark to jump to | |
426 return "\<CR>:norm! `" | |
427 elseif cmdline =~ '\C^undol' | |
428 " like :undolist but prompts for a change to undo | |
429 return "\<CR>:u " | |
430 else | |
431 return "\<CR>" | |
432 endif | |
433 endfunction | |
434 cnoremap <expr> <CR> CCR() | |
435 " }}} | |
436 | |
437 " Text objects {{{ | |
438 function! s:inIndentation() | |
439 " select all text in current indentation level excluding any empty lines | |
440 " that precede or follow the current indentationt level; | |
441 " | |
442 " the current implementation is pretty fast, even for many lines since it | |
443 " uses "search()" with "\%v" to find the unindented levels | |
444 " | |
445 " NOTE: if the current level of indentation is 1 (ie in virtual column 1), | |
446 " then the entire buffer will be selected | |
447 " | |
448 " WARNING: python devs have been known to become addicted to this | |
449 " magic is needed for this | |
450 let l:magic = &magic | |
451 set magic | |
452 | |
453 " move to beginning of line and get virtcol (current indentation level) | |
454 " BRAM: there is no searchpairvirtpos() ;) | |
455 normal! ^ | |
456 let l:vCol = virtcol(getline('.') =~# '^\s*$' ? '$' : '.') | |
457 | |
458 " pattern matching anything except empty lines and lines with recorded | |
459 " indentation level | |
460 let l:pat = '^\(\s*\%'.l:vCol.'v\|^$\)\@!' | |
461 | |
462 " find first match (backwards & don't wrap or move cursor) | |
463 let l:start = search(l:pat, 'bWn') + 1 | |
464 | |
465 " next, find first match (forwards & don't wrap or move cursor) | |
466 let l:end = search(l:pat, 'Wn') | |
467 | |
468 if (l:end !=# 0) | |
469 " if search succeeded, it went too far, so subtract 1 | |
470 let l:end -= 1 | |
471 endif | |
472 | |
473 " go to start (this includes empty lines) and--importantly--column 0 | |
474 execute 'normal! '.l:start.'G0' | |
475 | |
476 " skip empty lines (unless already on one .. need to be in column 0) | |
477 call search('^[^\n\r]', 'Wc') | |
478 | |
479 " go to end (this includes empty lines) | |
480 execute 'normal! Vo'.l:end.'G' | |
481 | |
482 " skip backwards to last selected non-empty line | |
483 call search('^[^\n\r]', 'bWc') | |
484 | |
485 " go to end-of-line 'cause why not | |
486 normal! $o | |
487 | |
488 " restore magic | |
489 let &magic = l:magic | |
490 endfunction | |
491 | |
492 " "in indentation" (indentation level sans any surrounding empty lines) | |
493 xnoremap <silent> ii :<c-u>call <sid>inIndentation()<cr> | |
494 onoremap <silent> ii :<c-u>call <sid>inIndentation()<cr> | |
495 | |
496 function! s:aroundIndentation() | |
497 " select all text in the current indentation level including any emtpy | |
498 " lines that precede or follow the current indentation level; | |
499 " | |
500 " the current implementation is pretty fast, even for many lines since it | |
501 " uses "search()" with "\%v" to find the unindented levels | |
502 " | |
503 " NOTE: if the current level of indentation is 1 (ie in virtual column 1), | |
504 " then the entire buffer will be selected | |
505 " | |
506 " WARNING: python devs have been known to become addicted to this | |
507 | |
508 " magic is needed for this (/\v doesn't seem work) | |
509 let l:magic = &magic | |
510 set magic | |
511 | |
512 " move to beginning of line and get virtcol (current indentation level) | |
513 " BRAM: there is no searchpairvirtpos() ;) | |
514 normal! ^ | |
515 let l:vCol = virtcol(getline('.') =~# '^\s*$' ? '$' : '.') | |
516 | |
517 " pattern matching anything except empty lines and lines with recorded | |
518 " indentation level | |
519 let l:pat = '^\(\s*\%'.l:vCol.'v\|^$\)\@!' | |
520 | |
521 " find first match (backwards & don't wrap or move cursor) | |
522 let l:start = search(l:pat, 'bWn') + 1 | |
523 | |
524 " NOTE: if l:start is 0, then search() failed; otherwise search() succeeded | |
525 " and l:start does not equal line('.') | |
526 " FORMER: l:start is 0; so, if we add 1 to l:start, then it will match | |
527 " everything from beginning of the buffer (if you don't like | |
528 " this, then you can modify the code) since this will be the | |
529 " equivalent of "norm! 1G" below | |
530 " LATTER: l:start is not 0 but is also not equal to line('.'); therefore, | |
531 " we want to add one to l:start since it will always match one | |
532 " line too high if search() succeeds | |
533 | |
534 " next, find first match (forwards & don't wrap or move cursor) | |
535 let l:end = search(l:pat, 'Wn') | |
536 | |
537 " NOTE: if l:end is 0, then search() failed; otherwise, if l:end is not | |
538 " equal to line('.'), then the search succeeded. | |
539 " FORMER: l:end is 0; we want this to match until the end-of-buffer if it | |
540 " fails to find a match for same reason as mentioned above; | |
541 " again, modify code if you do not like this); therefore, keep | |
542 " 0--see "NOTE:" below inside the if block comment | |
543 " LATTER: l:end is not 0, so the search() must have succeeded, which means | |
544 " that l:end will match a different line than line('.') | |
545 | |
546 if (l:end !=# 0) | |
547 " if l:end is 0, then the search() failed; if we subtract 1, then it | |
548 " will effectively do "norm! -1G" which is definitely not what is | |
549 " desired for probably every circumstance; therefore, only subtract one | |
550 " if the search() succeeded since this means that it will match at least | |
551 " one line too far down | |
552 " NOTE: exec "norm! 0G" still goes to end-of-buffer just like "norm! G", | |
553 " so it's ok if l:end is kept as 0. As mentioned above, this means | |
554 " that it will match until end of buffer, but that is what I want | |
555 " anyway (change code if you don't want) | |
556 let l:end -= 1 | |
557 endif | |
558 | |
559 " finally, select from l:start to l:end | |
560 execute 'normal! '.l:start.'G0V'.l:end.'G$o' | |
561 | |
562 " restore magic | |
563 let &magic = l:magic | |
564 endfunction | |
565 | |
566 " "around indentation" (indentation level and any surrounding empty lines) | |
567 xnoremap <silent> ai :<c-u>call <sid>aroundIndentation()<cr> | |
568 onoremap <silent> ai :<c-u>call <sid>aroundIndentation()<cr> | |
569 " }}} | |
570 " }}} | |
571 | |
572 " Filetype specific settings {{{ | |
573 " Text {{{ | |
574 augroup ft_text | |
575 au! | |
576 " au BufNewFile,BufRead,BufEnter *.txt setlocal spell spelllang=en_gb | |
577 au BufNewFile,BufRead,BufEnter *.txt setlocal textwidth=0 | |
578 augroup END | |
579 augroup ft_report | |
580 au! | |
581 au BufNewFile,BufRead,BufEnter *.rpt setlocal nowrap | |
582 au BufNewFile,BufRead,BufEnter *.rpt call ColorRpt() | |
583 au BufNewFile,BufRead,BufEnter *.log call ColorRpt() | |
584 augroup END | |
585 | |
586 function! ColorRpt() | |
587 " Color numbers based on length | |
423 | 588 syn match String "\v<\d{1,3}>" |
589 syn match Number "\v<\d{4,6}>" | |
411 | 590 syn match Statement "\v<\d{7,9}>" |
591 | |
592 " Color errors | |
593 syn match Error "\v^ERROR:.*$" | |
594 endfunction | |
595 " }}} | |
596 " Git commit messages {{{ | |
597 augroup ft_git | |
598 au! | |
599 au FileType gitcommit setlocal spell spelllang=en_gb | |
600 autocmd FileType gitcommit,gitrebase,gitconfig set bufhidden=delete | |
601 augroup END | |
602 " }}} | |
603 " Ruby {{{ | |
604 augroup ft_ruby | |
605 au! | |
606 autocmd BufRead *_spec.rb set filetype=rspec | |
607 augroup END | |
608 " }}} | |
609 " Matlab {{{ | |
610 augroup ft_matlab | |
611 au! | |
612 autocmd FileType matlab setlocal commentstring=\%\ %s | |
613 augroup END | |
614 " }}} | |
615 " C {{{ | |
616 augroup ft_c | |
617 au! | |
618 au FileType c setlocal foldmethod=syntax | |
619 augroup END | |
620 " }}} | |
621 " TCL {{{ | |
622 | |
623 augroup ft_tcl | |
624 au! | |
625 autocmd FileType tcl setlocal commentstring=#\ %s | |
626 " autocmd FileType tcl compiler nagelfar | |
627 autocmd BufRead *.do set filetype=tcl | |
628 autocmd BufRead *.hal set filetype=tcl | |
629 autocmd FileType tcl setlocal iskeyword+=: | |
630 autocmd FileType tcl setlocal breakat-=: | |
631 autocmd FileType tcl setlocal suffixesadd+=.tcl,.do | |
632 augroup END | |
633 " shortcuts | |
634 iabbrev procargs array set arg [::argument_processing::proces_arguments $args]; | |
635 " }}} | |
636 " GPG {{{ | |
637 " Don't save backups of gpg asc files | |
638 set backupskip+=*.asc | |
639 | |
640 " Convenient editing of ascii-armoured encrypted files | |
641 augroup GPGASCII | |
642 au! | |
643 au BufReadPost *.asc :%!gpg -q -d | |
644 au BufReadPost *.asc |redraw | |
645 au BufWritePre *.asc :%!gpg -q -e -a | |
646 au BufWritePost *.asc u | |
647 au VimLeave *.asc :!clear | |
648 augroup END | |
649 " }}} | |
650 " System Verilog {{{ | |
651 augroup ft_systemverilog | |
652 au! | |
653 au FileType systemverilog setlocal suffixesadd+=.sv,.v | |
654 au FileType systemverilog setlocal foldmethod=expr | |
655 au FileType systemverilog setlocal foldexpr=nvim_treesitter#foldexpr() | |
656 au FileType systemverilog,verilog call SVAlign() | |
657 au FileType systemverilog,verilog let b:delimitMate_quotes = "\"" | |
658 au FileType systemverilog,verilog set iskeyword+=' | |
659 augroup END | |
660 | |
661 function! SVAlign() | |
662 let g:easy_align_delimiters = { | |
663 \ ')': { 'pattern': '[()]', 'left_margin': 0, 'right_margin': 0, 'stick_to_left': 0} | |
664 \} | |
665 endfunction | |
666 " }}} | |
667 " Make {{{ | |
668 augroup ft_make | |
669 autocmd! | |
670 autocmd BufEnter *.make setlocal filetype=make | |
671 autocmd FileType make setlocal noexpandtab | |
672 augroup END | |
673 " JSON {{{ | |
674 augroup ft_json | |
675 autocmd! | |
676 autocmd FileType json setlocal equalprg=jq | |
677 augroup END | |
678 " }}} | |
679 " }}} | |
680 " Python {{{ | |
681 augroup f_python | |
682 autocmd! | |
683 autocmd FileType python setlocal shiftwidth=4 | |
684 au FileType python setlocal formatprg=autopep8\ - | |
685 autocmd FileType python setlocal path-=** | |
686 autocmd Filetype python let b:delimitMate_nesting_quotes = ['"', "'"] | |
687 augroup END | |
688 | |
689 let g:python_highlight_all=1 | |
690 " }}} | |
691 " }}} | |
692 | |
693 " Plugin settings {{{ | |
694 " Gundo tree {{{ | |
695 nnoremap <leader>u :GundoToggle<CR> | |
696 " }}} | |
697 " Projectionist {{{ | |
698 let g:projectionist_heuristics = { | |
699 \ "*.c": { | |
700 \ "*.c": { | |
701 \ "alternate": "{}.h", | |
702 \ "type": "source", | |
703 \ "template": ["#include \"{}.h\""], | |
704 \ "make": "make -wC {project}" | |
705 \ }, | |
706 \ "*.h": { | |
707 \ "alternate": "{}.c", | |
708 \ "type": "header", | |
709 \ "template": ["#ifndef {uppercase}_H", "#define {uppercase}_H", "", "#endif"] | |
710 \ }, | |
711 \ "Makefile": {"type": "makefile"}, | |
712 \ }, | |
713 \ "*.py": { | |
714 \ "*.py": { "make": "ipython {}" } | |
715 \ }, | |
716 \ } | |
717 " }}} | |
718 " Grep {{{ | |
719 let g:grepper = { | |
720 \ 'tools': ['ag', 'hg'], | |
721 \ 'highlight': 1, | |
423 | 722 \ 'ag': { |
411 | 723 \ 'grepprg': 'rg --vimgrep', |
724 \ }} | |
725 | |
726 nnoremap gs <plug>(GrepperOperator) | |
727 xnoremap gs <plug>(GrepperOperator) | |
728 | |
729 | |
730 command! -nargs=* -complete=file Ag Grepper -noprompt -tool ag -grepprg rg --vimgrep <args> | |
731 " }}} | |
732 " Vinegar/NetRW {{{ | |
733 autocmd FileType netrw setl bufhidden=delete | |
734 " }}} | |
735 " NCM {{{ | |
736 function! s:check_back_space() abort | |
737 let col = col('.') - 1 | |
738 return !col || getline('.')[col - 1] =~# '\s' | |
739 endfunction | |
740 | |
741 " Auto close popup menu when finish completion | |
742 autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif | |
743 | |
744 " Use <Tab> and <S-Tab> to navigate through popup menu | |
745 inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>" | |
746 inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>" | |
747 | |
748 " Set completeopt to have a better completion experience | |
749 set completeopt=menuone,noinsert,noselect | |
750 | |
751 " Avoid showing message extra message when using completion | |
752 set shortmess+=c | |
753 | |
754 let g:completion_enable_snippet = 'UltiSnips' | |
755 let g:UltiSnipsJumpForwardTrigger="<c-b>" | |
756 let g:UltiSnipsJumpBackwardTrigger="<c-z>" | |
757 let g:completion_enable_auto_paren=0 | |
758 | |
759 imap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>' | |
760 smap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>' | |
761 imap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>' | |
762 smap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>' | |
763 | |
764 " }}} | |
765 " }}} | |
766 " }}} | |
767 | |
768 function! SendOSCClipboard(lines, regtype) | |
769 call SendViaOSC52(join(a:lines, "\n")) | |
770 endfunction | |
771 | |
772 let g:clipboard = { | |
773 \ 'name': 'TMUX', | |
774 \ 'copy': { | |
775 \ '+': function('SendOSCClipboard'), | |
776 \ '*': 'tmux load-buffer -', | |
777 \ }, | |
778 \ 'paste': { | |
779 \ '+': 'tmux save-buffer -', | |
780 \ '*': 'tmux save-buffer -', | |
781 \ }, | |
782 \ 'cache_enabled': 1, | |
783 \ } | |
784 " Load local vimrc | |
785 if filereadable($HOME . '/.vimrc.local') | |
786 source ~/.vimrc.local | |
787 endif | |
788 | |
789 " Load project local vimrc | |
790 if filereadable('.vimrc.local') | |
791 source .vimrc.local | |
792 endif | |
793 | |
421
04d84cc8e59a
Automatically apply chezmoi config when saving
zegervdv <zegervdv@me.com>
parents:
411
diff
changeset
|
794 augroup Chezmoi |
04d84cc8e59a
Automatically apply chezmoi config when saving
zegervdv <zegervdv@me.com>
parents:
411
diff
changeset
|
795 autocmd! |
04d84cc8e59a
Automatically apply chezmoi config when saving
zegervdv <zegervdv@me.com>
parents:
411
diff
changeset
|
796 autocmd BufWritePost ~/.local/share/chezmoi/* silent !chezmoi apply --source-path % |
04d84cc8e59a
Automatically apply chezmoi config when saving
zegervdv <zegervdv@me.com>
parents:
411
diff
changeset
|
797 augroup END |