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