Mercurial > dotfiles
annotate dot_config/nvim/plugin/config.vim @ 421:04d84cc8e59a
Automatically apply chezmoi config when saving
author | zegervdv <zegervdv@me.com> |
---|---|
date | Tue, 27 Jul 2021 18:31:24 +0200 |
parents | 4abd1fbc8829 |
children | 5683e8e3e361 |
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 " Backspace over everything, like normal | |
29 set backspace=2 | |
30 | |
31 " Buffers | |
32 set autoread " Read external changes | |
33 set hidden " Change between buffers without saving | |
34 set autowriteall " Write changes when losing focus | |
35 | |
36 " Visuals | |
37 set number | |
38 set relativenumber | |
39 set ruler | |
40 syntax on | |
41 set title | |
42 set scrolloff=4 " Stay 4 lines from top/bottom | |
43 set showcmd | |
44 | |
45 " Theme and style | |
46 | |
47 set termguicolors | |
48 | |
49 set background=dark | |
50 | |
51 if s:windows | |
52 set background=light | |
53 colorscheme PaperColor | |
54 set guifont=consolas:h10 | |
55 endif | |
56 | |
57 set showmatch " Highlight matching brackets | |
58 | |
59 set wrap " Wrap lines | |
60 set wrapmargin=2 " Stay 2 chars from side | |
61 set textwidth=79 | |
62 set colorcolumn=81 | |
63 set linebreak " Smarter wrapping | |
64 if v:version > 703 | |
65 set breakindent " Indent wrapped lines to same level | |
66 endif | |
67 | |
68 set fixendofline | |
69 | |
70 set expandtab " Expand tabs to spaces | |
71 set tabstop=2 shiftwidth=2 " Tab is 2 spaces | |
72 | |
73 set shiftround " Round shift indents to nearest value | |
74 | |
75 " Searching | |
76 set magic " Use magic regexes | |
77 set hlsearch " Highlight all matches | |
78 set incsearch " Show matches while typing | |
79 set ignorecase " Ignore case when searching | |
80 set smartcase " Be case sensitive if at least one uppercase char is used | |
81 set gdefault " Default substitute all matches on a line | |
82 if has('nvim') | |
83 set inccommand=nosplit | |
84 endif | |
85 | |
86 set autoindent " Automatically indent | |
87 set cindent " Indent based on C syntax | |
88 set cinwords+=foreach | |
89 | |
90 set updatetime=300 | |
91 | |
92 if s:darwin | |
93 set vb | |
94 endif | |
95 set noerrorbells " Don't beep | |
96 | |
97 set guioptions-=r | |
98 set guioptions-=l | |
99 set guioptions-=R | |
100 set guioptions-=L | |
101 set guioptions-=a | |
102 set guioptions-=m | |
103 set guioptions-=T | |
104 set guioptions+=c | |
105 | |
106 set history=100 " Set history 100 | |
107 set wildmenu " Command completion | |
108 set wildmode=longest:full,full " Complete to fullest match | |
109 set ttyfast " Use a fast terminal | |
110 set lazyredraw " No need to redraw constantly | |
111 set shortmess+=c | |
112 | |
113 set ttimeoutlen=-1 " Set the timeout to a minimum | |
114 set diffopt+=iwhite " Ignore spaces in diffs" | |
115 set diffopt+=internal,algorithm:patience " use patience algorithm for better diffs | |
116 | |
117 set tags=.git/tags,tags,/project/asic_fpga/tools/vim/share/vim/vimfiles/tags | |
118 | |
119 " Have find look through all folders | |
120 set path+=** | |
121 " Add PRJROOT and subdirs to path if it is set | |
122 if exists('$PRJROOT') | |
123 set path+=$PRJROOT/** | |
124 endif | |
125 | |
126 set formatoptions= | |
127 set formatoptions+=c " Format comments | |
128 set formatoptions+=r " Continue comments by default | |
129 set formatoptions+=o " Make comment when using o or O from comment line | |
130 set formatoptions+=q " Format comments with gq | |
131 set formatoptions+=n " Recognize numbered lists | |
132 set formatoptions+=2 " Use indent from 2nd line of a paragraph | |
133 " set formatoptions+=l " Don't break lines that are already long | |
134 set formatoptions+=1 " Break before 1-letter words | |
135 | |
136 set signcolumn=yes | |
137 | |
138 " Enable cursorline | |
139 set cursorline | |
140 augroup cline | |
141 au! | |
142 autocmd WinEnter * setlocal cursorline | |
143 autocmd WinLeave * setlocal nocursorline | |
144 augroup END | |
145 | |
146 if !s:windows | |
147 set list | |
148 set listchars=tab:»\ ,trail:·,extends:>,precedes:<,nbsp:+ | |
149 endif | |
150 | |
151 set sessionoptions-=options | |
152 | |
153 " Scan files for completion | |
154 set complete=.,w,b,u,k,kspell,t,i,d | |
155 set completeopt=menu,menuone,noselect | |
156 | |
157 set splitright | |
158 set virtualedit=block | |
159 | |
160 if v:version > 703 | |
161 set conceallevel=0 | |
162 if !has('nvim') | |
163 set cryptmethod=blowfish2 | |
164 endif | |
165 endif | |
166 | |
167 filetype plugin indent on | |
168 | |
169 set pastetoggle=<F2> " Toggle to paste mode | |
170 | |
171 if v:version >= 703 | |
172 set undofile | |
173 endif | |
174 set undolevels=1000 | |
175 set backup | |
176 set noswapfile | |
177 if has('nvim') | |
178 " set viminfo+=n~/.config/nvim/.viminfo | |
179 set backupdir=~/.config/nvim/tmp/backup/,. | |
180 set directory=~/.config/nvim/tmp/swap//,. | |
181 else | |
182 set viminfo+=n~/.vim/.viminfo | |
183 set backupdir=~/.vim/tmp/backup/,. | |
184 set directory=~/.vim/tmp/swap//,. | |
185 endif | |
186 if !isdirectory(expand(&backupdir)) | |
187 call mkdir(expand(&backupdir), "p") | |
188 endif | |
189 if !isdirectory(expand(&directory)) | |
190 call mkdir(expand(&directory), "p") | |
191 endif | |
192 | |
193 if v:version >= 703 | |
194 if has('nvim') | |
195 set undodir=~/.config/nvim/tmp/undo//,. | |
196 else | |
197 set undodir=~/.vim/tmp/undo//,. | |
198 endif | |
199 if !isdirectory(expand(&undodir)) | |
200 call mkdir(expand(&undodir), "p") | |
201 endif | |
202 endif | |
203 | |
204 | |
205 set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.o,*.bin,*.elf,*.hex,*.eps,.git/**,*.dup,.hg/**,*.orig,*.*~ | |
206 | |
207 " No selecting via mouse (stops visual selection when scrolling) | |
208 set mouse=nic | |
209 | |
210 " }}} | |
211 | |
212 " Mappings {{{ | |
213 " Set leader to spacebar | |
214 map <space> <leader> | |
215 | |
216 " See long lines as line breaks | |
217 noremap <expr> j (v:count? 'j' : 'gj') | |
218 noremap <expr> k (v:count? 'k' : 'gk') | |
219 | |
220 " Remap tag-search to better place | |
221 nnoremap <C-$> g<C-]> | |
222 nnoremap <C-w>y <C-w>g<C-]> | |
223 | |
224 nnoremap <C-s> <C-e> | |
225 | |
226 " Move while in insert mode | |
227 inoremap <C-f> <right> | |
228 | |
229 " Switch between the last two files | |
230 " nnoremap <space><space> <C-^> | |
231 | |
232 " " Very Magic search patterns | |
233 nnoremap / /\v | |
234 vnoremap / /\v | |
235 | |
236 " Keep search matches in the middle of the window. | |
237 nnoremap n nzzzv | |
238 nnoremap N Nzzzv | |
239 | |
240 " Search for beginning of command | |
241 cnoremap <c-n> <down> | |
242 cnoremap <c-p> <up> | |
243 | |
244 " Move whole lines | |
245 nnoremap [e :<c-u>execute 'move -1-'. v:count1<cr> | |
246 nnoremap ]e :<c-u>execute 'move +'. v:count1<cr> | |
247 | |
248 " Insert empty lines | |
249 nnoremap [<space> :<c-u>put! =repeat(nr2char(10), v:count1)<cr>'[ | |
250 nnoremap ]<space> :<c-u>put =repeat(nr2char(10), v:count1)<cr> | |
251 | |
252 " Clear highlight | |
253 nnoremap <silent><leader>l :noh<CR> | |
254 | |
255 inoremap £ \ | |
256 | |
257 " Highlight last inserted text | |
258 nnoremap gV `[v`] | |
259 | |
260 " Highlight VCS conflict markers | |
261 match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$' | |
262 | |
263 " Use backspace as delete in visual mode | |
264 vmap <BS> x | |
265 | |
266 " Redraw screen | |
267 nnoremap <F3> :redraw!<CR> | |
268 | |
269 " Keep selection when shifting | |
270 vmap <expr> > KeepVisualSelection(">") | |
271 vmap <expr> < KeepVisualSelection("<") | |
272 | |
273 function! KeepVisualSelection(cmd) | |
274 set nosmartindent | |
275 if mode() ==# "V" | |
276 return a:cmd . ":set smartindent\<CR>gv" | |
277 else | |
278 return a:cmd . ":set smartindent\<CR>" | |
279 endif | |
280 endfunction | |
281 | |
282 " Swap backticks and quotes | |
283 nnoremap ` ' | |
284 nnoremap ' ` | |
285 | |
286 " Open vimrc | |
287 nnoremap <leader>ve :e $MYVIMRC<CR> | |
288 nnoremap <leader>vs :so $MYVIMRC<CR> | |
289 | |
290 " Open dup in diffmode | |
291 nnoremap <leader>d :call OpenDup(@%)<CR> | |
292 | |
293 function! OpenDup(file) | |
294 let l:filename = a:file . ".dup" | |
295 execute 'vsplit' l:filename | |
296 windo diffthis | |
297 endfunction | |
298 | |
299 " Do not move on * | |
300 nnoremap <silent> * :let stay_star_view = winsaveview()<cr>*:call winrestview(stay_star_view)<cr> | |
301 | |
302 " Search for selected text, forwards or backwards. | |
303 vnoremap <silent> * :<C-U> | |
304 \let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR> | |
305 \gvy/<C-R><C-R>=substitute( | |
306 \escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR> | |
307 \gV:call setreg('"', old_reg, old_regtype)<CR> | |
308 vnoremap <silent> # :<C-U> | |
309 \let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR> | |
310 \gvy?<C-R><C-R>=substitute( | |
311 \escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR> | |
312 \gV:call setreg('"', old_reg, old_regtype)<CR> | |
313 | |
314 " nnoremap <F10> :botright copen<CR> | |
315 | |
316 xnoremap <silent> p p:if v:register == '"'<Bar>let @@=@0<Bar>endif<CR> | |
317 | |
318 " Error navigation | |
319 nnoremap <UP> :cprev<CR> | |
320 nnoremap <DOWN> :cnext<CR> | |
321 nnoremap <RIGHT> :cnf<CR> | |
322 nnoremap <LEFT> :cpf<CR> | |
323 | |
324 nnoremap <leader>y :ptjump <c-r><c-w><CR> | |
325 | |
326 function! ToggleDiff() | |
327 if &diff == 1 | |
328 windo diffoff | |
329 else | |
330 windo diffthis | |
331 endif | |
332 endfunction | |
333 nnoremap <leader>g :call ToggleDiff()<CR> | |
334 | |
335 if has('nvim') | |
336 tnoremap <C-h> <C-\><C-n><C-w>h | |
337 tnoremap <C-j> <C-\><C-n><C-w>j | |
338 tnoremap <C-k> <C-\><C-n><C-w>k | |
339 tnoremap <C-l> <C-\><C-n><C-w>l | |
340 augroup enter_term | |
341 au! | |
342 autocmd TermOpen * startinsert! | |
343 autocmd BufEnter * if &buftype ==# 'terminal' | :startinsert! | endif | |
344 autocmd BufLeave * if &buftype ==# 'terminal' | :stopinsert! | endif | |
345 augroup END | |
346 let $GIT_EDITOR = 'nvr -cc split --remote-wait' | |
347 endif | |
348 | |
349 " Open buffers, tags... in vertical splits | |
350 nnoremap <leader>b :vert sbuffer | |
351 nnoremap <leader>t :vert stjump | |
352 nnoremap <leader>f :vert sfind | |
353 | |
354 | |
355 " }}} | |
356 | |
357 " Functions {{{ | |
358 " When editing a file, always jump to the last known cursor position. | |
359 " Don't do it for commit messages, when the position is invalid, or when | |
360 " inside an event handler (happens when dropping a file on gvim). | |
361 autocmd BufReadPost * | |
362 \ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") | | |
363 \ exe "normal g`\"" | | |
364 \ endif | |
365 | |
366 " Thg mappings | |
367 function! s:HGhist(file) | |
368 if !empty(a:file) | |
369 let path = a:file | |
370 else | |
371 let path = expand('%') | |
372 endif | |
373 exec 'silent! !thg filelog ' . path . ' &' | |
374 endfunction | |
375 | |
376 command! -nargs=? -complete=file HGhist call s:HGhist(<q-args>) | |
377 | |
378 augroup focus_lost | |
379 au! | |
380 au FocusLost * if !&readonly | :wa | endif | |
381 augroup END | |
382 | |
383 augroup LuaHighlight | |
384 autocmd! | |
385 autocmd TextYankPost * silent! lua require'vim.highlight'.on_yank() | |
386 augroup END | |
387 | |
388 " Resize splits after window resize {{{ | |
389 augroup vim_resize | |
390 au! | |
391 au VimResized * exe "normal! \<c-w>=" | |
392 augroup END | |
393 " }}} | |
394 | |
395 " Automatically reload vimrc when saving {{{ | |
396 augroup reload_vim | |
397 autocmd! | |
398 autocmd BufWritePost $MYVIMRC nested source $MYVIMRC | |
399 augroup END | |
400 " }}} | |
401 | |
402 " Reload diffs {{{ | |
403 augroup diff_files | |
404 au! | |
405 au BufWritePost * if &diff == 1 | diffupdate | endif | |
406 augroup END | |
407 " }}} | |
408 | |
409 " Custom folding by Steve Losh | |
410 function! MyFoldText() " {{{ | |
411 let line = getline(v:foldstart) | |
412 | |
413 let nucolwidth = &fdc + &number * &numberwidth | |
414 let windowwidth = winwidth(0) - nucolwidth - 3 | |
415 let foldedlinecount = v:foldend - v:foldstart | |
416 | |
417 " expand tabs into spaces | |
418 let onetab = strpart(' ', 0, &tabstop) | |
419 let line = substitute(line, '\t', onetab, 'g') | |
420 | |
421 let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount)) | |
422 let fillcharcount = windowwidth - len(line) - len(foldedlinecount) | |
423 return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' ' | |
424 endfunction " }}} | |
425 set foldtext=MyFoldText() | |
426 set foldopen+=jump | |
427 | |
428 " Detect Filetype from content if file has no extension {{{ | |
429 augroup newFileDetection | |
430 au! | |
431 autocmd CursorMovedI * call CheckFileType() | |
432 augroup END | |
433 | |
434 function! CheckFileType() | |
435 if exists("b:countCheck") == 0 | |
436 let b:countCheck = 0 | |
437 endif | |
438 let b:countCheck += 1 | |
439 if &filetype == "" && b:countCheck > 20 && b:countCheck < 200 | |
440 filetype detect | |
441 " Delete the function if no filetype can be established, or the type has | |
442 " been found | |
443 elseif b:countCheck >= 200 || &filetype != "" | |
444 autocmd! newFileDetection | |
445 endif | |
446 endfunction | |
447 " }}} | |
448 | |
449 " Convert hex <-> decimal {{{ | |
450 command! -nargs=? -range Dec2hex call s:Dec2hex(<line1>, <line2>, '<args>') | |
451 function! s:Dec2hex(line1, line2, arg) range | |
452 if empty(a:arg) | |
453 if histget(':', -1) =~# "^'<,'>" && visualmode() !=# 'V' | |
454 let cmd = 's/\%V\<\d\+\>/\=printf("0x%x",submatch(0)+0)/g' | |
455 else | |
456 let cmd = 's/\<\d\+\>/\=printf("0x%x",submatch(0)+0)/g' | |
457 endif | |
458 try | |
459 execute a:line1 . ',' . a:line2 . cmd | |
460 catch | |
461 echo 'Error: No decimal number found' | |
462 endtry | |
463 else | |
464 echo printf('%x', a:arg + 0) | |
465 endif | |
466 endfunction | |
467 | |
468 command! -nargs=? -range Hex2dec call s:Hex2dec(<line1>, <line2>, '<args>') | |
469 function! s:Hex2dec(line1, line2, arg) range | |
470 if empty(a:arg) | |
471 if histget(':', -1) =~# "^'<,'>" && visualmode() !=# 'V' | |
472 let cmd = 's/\%V0x\x\+/\=submatch(0)+0/g' | |
473 else | |
474 let cmd = 's/0x\x\+/\=submatch(0)+0/g' | |
475 endif | |
476 try | |
477 execute a:line1 . ',' . a:line2 . cmd | |
478 catch | |
479 echo 'Error: No hex number starting "0x" found' | |
480 endtry | |
481 else | |
482 echo (a:arg =~? '^0x') ? a:arg + 0 : ('0x'.a:arg) + 0 | |
483 endif | |
484 endfunction | |
485 " }}} | |
486 | |
487 " Recognize filetype for dup files {{{ | |
488 autocmd! BufRead *.dup call DupSetSyntax(@%) | |
489 | |
490 function! DupSetSyntax(name) | |
491 let extension = matchlist(a:name, '\v.+.\.([^\.]+).dup')[1] | |
492 if extension == "vhd" | |
493 setlocal filetype=vhdl | |
494 elseif extension == "v" | |
495 setlocal filetype=verilog | |
496 elseif extension == "sv" | |
497 setlocal filetype=verilog | |
498 else | |
499 echo "Unknown filetype" | |
500 endif | |
501 endfunction | |
502 " }}} | |
503 | |
504 " Create arguments list from files in quickfix list | |
505 " Allows to Grep for a pattern and apply an argdo command on each of the | |
506 " matching files {{{ | |
507 command! -nargs=0 -bar Qargs execute 'args' QuickfixFilenames() | |
508 function! QuickfixFilenames() | |
509 " Building a hash ensures we get each buffer only once | |
510 let buffer_numbers = {} | |
511 for quickfix_item in getqflist() | |
512 let buffer_numbers[quickfix_item['bufnr']] = bufname(quickfix_item['bufnr']) | |
513 endfor | |
514 return join(map(values(buffer_numbers), 'fnameescape(v:val)')) | |
515 endfunction | |
516 "}}} | |
517 | |
518 augroup mark_files | |
519 au! | |
520 au BufLeave test.tcl mark T | |
521 au BufLeave case.do mark C | |
522 au BufLeave drv_*.tcl mark D | |
523 au BufLeave *.rtl.vhd mark R | |
524 augroup END | |
525 | |
526 | |
527 " Toggle between opening/closing the quickfix window {{{ | |
528 function! GetBufferList() | |
529 redir =>buflist | |
530 silent! ls! | |
531 redir END | |
532 return buflist | |
533 endfunction | |
534 | |
535 function! ToggleList(bufname, pfx) | |
536 let buflist = GetBufferList() | |
537 for bufnum in map(filter(split(buflist, '\n'), 'v:val =~ "'.a:bufname.'"'), 'str2nr(matchstr(v:val, "\\d\\+"))') | |
538 if bufwinnr(bufnum) != -1 | |
539 exec(a:pfx.'close') | |
540 return | |
541 endif | |
542 endfor | |
543 if a:pfx == 'l' && len(getloclist(0)) == 0 | |
544 echohl ErrorMsg | |
545 echo "Location List is Empty." | |
546 return | |
547 endif | |
548 let winnr = winnr() | |
549 exec('botright '.a:pfx.'open') | |
550 if winnr() != winnr | |
551 wincmd p | |
552 endif | |
553 endfunction | |
554 | |
555 nnoremap <silent> <F10> :call ToggleList("Quickfix List", 'c')<CR> | |
556 " }}} | |
557 | |
558 | |
559 " Make list-like commands more intuitive {{{ | |
560 " Copied from https://gist.github.com/romainl/047aca21e338df7ccf771f96858edb86 | |
561 function! CCR() | |
562 let cmdline = getcmdline() | |
563 if cmdline =~ '\v\C^(ls|files|buffers)' | |
564 " like :ls but prompts for a buffer command | |
565 return "\<CR>:b" | |
566 elseif cmdline =~ '\v\C/(#|nu|num|numb|numbe|number)$' | |
567 " like :g//# but prompts for a command | |
568 return "\<CR>:" | |
569 elseif cmdline =~ '\v\C^(dli|il)' | |
570 " like :dlist or :ilist but prompts for a count for :djump or :ijump | |
571 return "\<CR>:" . cmdline[0] . "j " . split(cmdline, " ")[1] . "\<S-Left>\<Left>" | |
572 elseif cmdline =~ '\v\C^(cli|lli)' | |
573 " like :clist or :llist but prompts for an error/location number | |
574 return "\<CR>:sil " . repeat(cmdline[0], 2) . "\<Space>" | |
575 elseif cmdline =~ '\C^old' | |
576 " like :oldfiles but prompts for an old file to edit | |
577 set nomore | |
578 return "\<CR>:sil se more|e #<" | |
579 elseif cmdline =~ '\C^changes' | |
580 " like :changes but prompts for a change to jump to | |
581 set nomore | |
582 return "\<CR>:sil se more|norm! g;\<S-Left>" | |
583 elseif cmdline =~ '\C^ju' | |
584 " like :jumps but prompts for a position to jump to | |
585 set nomore | |
586 return "\<CR>:sil se more|norm! \<C-o>\<S-Left>" | |
587 elseif cmdline =~ '\C^marks' | |
588 " like :marks but prompts for a mark to jump to | |
589 return "\<CR>:norm! `" | |
590 elseif cmdline =~ '\C^undol' | |
591 " like :undolist but prompts for a change to undo | |
592 return "\<CR>:u " | |
593 else | |
594 return "\<CR>" | |
595 endif | |
596 endfunction | |
597 cnoremap <expr> <CR> CCR() | |
598 " }}} | |
599 | |
600 " Text objects {{{ | |
601 function! s:inIndentation() | |
602 " select all text in current indentation level excluding any empty lines | |
603 " that precede or follow the current indentationt level; | |
604 " | |
605 " the current implementation is pretty fast, even for many lines since it | |
606 " uses "search()" with "\%v" to find the unindented levels | |
607 " | |
608 " NOTE: if the current level of indentation is 1 (ie in virtual column 1), | |
609 " then the entire buffer will be selected | |
610 " | |
611 " WARNING: python devs have been known to become addicted to this | |
612 " magic is needed for this | |
613 let l:magic = &magic | |
614 set magic | |
615 | |
616 " move to beginning of line and get virtcol (current indentation level) | |
617 " BRAM: there is no searchpairvirtpos() ;) | |
618 normal! ^ | |
619 let l:vCol = virtcol(getline('.') =~# '^\s*$' ? '$' : '.') | |
620 | |
621 " pattern matching anything except empty lines and lines with recorded | |
622 " indentation level | |
623 let l:pat = '^\(\s*\%'.l:vCol.'v\|^$\)\@!' | |
624 | |
625 " find first match (backwards & don't wrap or move cursor) | |
626 let l:start = search(l:pat, 'bWn') + 1 | |
627 | |
628 " next, find first match (forwards & don't wrap or move cursor) | |
629 let l:end = search(l:pat, 'Wn') | |
630 | |
631 if (l:end !=# 0) | |
632 " if search succeeded, it went too far, so subtract 1 | |
633 let l:end -= 1 | |
634 endif | |
635 | |
636 " go to start (this includes empty lines) and--importantly--column 0 | |
637 execute 'normal! '.l:start.'G0' | |
638 | |
639 " skip empty lines (unless already on one .. need to be in column 0) | |
640 call search('^[^\n\r]', 'Wc') | |
641 | |
642 " go to end (this includes empty lines) | |
643 execute 'normal! Vo'.l:end.'G' | |
644 | |
645 " skip backwards to last selected non-empty line | |
646 call search('^[^\n\r]', 'bWc') | |
647 | |
648 " go to end-of-line 'cause why not | |
649 normal! $o | |
650 | |
651 " restore magic | |
652 let &magic = l:magic | |
653 endfunction | |
654 | |
655 " "in indentation" (indentation level sans any surrounding empty lines) | |
656 xnoremap <silent> ii :<c-u>call <sid>inIndentation()<cr> | |
657 onoremap <silent> ii :<c-u>call <sid>inIndentation()<cr> | |
658 | |
659 function! s:aroundIndentation() | |
660 " select all text in the current indentation level including any emtpy | |
661 " lines that precede or follow the current indentation level; | |
662 " | |
663 " the current implementation is pretty fast, even for many lines since it | |
664 " uses "search()" with "\%v" to find the unindented levels | |
665 " | |
666 " NOTE: if the current level of indentation is 1 (ie in virtual column 1), | |
667 " then the entire buffer will be selected | |
668 " | |
669 " WARNING: python devs have been known to become addicted to this | |
670 | |
671 " magic is needed for this (/\v doesn't seem work) | |
672 let l:magic = &magic | |
673 set magic | |
674 | |
675 " move to beginning of line and get virtcol (current indentation level) | |
676 " BRAM: there is no searchpairvirtpos() ;) | |
677 normal! ^ | |
678 let l:vCol = virtcol(getline('.') =~# '^\s*$' ? '$' : '.') | |
679 | |
680 " pattern matching anything except empty lines and lines with recorded | |
681 " indentation level | |
682 let l:pat = '^\(\s*\%'.l:vCol.'v\|^$\)\@!' | |
683 | |
684 " find first match (backwards & don't wrap or move cursor) | |
685 let l:start = search(l:pat, 'bWn') + 1 | |
686 | |
687 " NOTE: if l:start is 0, then search() failed; otherwise search() succeeded | |
688 " and l:start does not equal line('.') | |
689 " FORMER: l:start is 0; so, if we add 1 to l:start, then it will match | |
690 " everything from beginning of the buffer (if you don't like | |
691 " this, then you can modify the code) since this will be the | |
692 " equivalent of "norm! 1G" below | |
693 " LATTER: l:start is not 0 but is also not equal to line('.'); therefore, | |
694 " we want to add one to l:start since it will always match one | |
695 " line too high if search() succeeds | |
696 | |
697 " next, find first match (forwards & don't wrap or move cursor) | |
698 let l:end = search(l:pat, 'Wn') | |
699 | |
700 " NOTE: if l:end is 0, then search() failed; otherwise, if l:end is not | |
701 " equal to line('.'), then the search succeeded. | |
702 " FORMER: l:end is 0; we want this to match until the end-of-buffer if it | |
703 " fails to find a match for same reason as mentioned above; | |
704 " again, modify code if you do not like this); therefore, keep | |
705 " 0--see "NOTE:" below inside the if block comment | |
706 " LATTER: l:end is not 0, so the search() must have succeeded, which means | |
707 " that l:end will match a different line than line('.') | |
708 | |
709 if (l:end !=# 0) | |
710 " if l:end is 0, then the search() failed; if we subtract 1, then it | |
711 " will effectively do "norm! -1G" which is definitely not what is | |
712 " desired for probably every circumstance; therefore, only subtract one | |
713 " if the search() succeeded since this means that it will match at least | |
714 " one line too far down | |
715 " NOTE: exec "norm! 0G" still goes to end-of-buffer just like "norm! G", | |
716 " so it's ok if l:end is kept as 0. As mentioned above, this means | |
717 " that it will match until end of buffer, but that is what I want | |
718 " anyway (change code if you don't want) | |
719 let l:end -= 1 | |
720 endif | |
721 | |
722 " finally, select from l:start to l:end | |
723 execute 'normal! '.l:start.'G0V'.l:end.'G$o' | |
724 | |
725 " restore magic | |
726 let &magic = l:magic | |
727 endfunction | |
728 | |
729 " "around indentation" (indentation level and any surrounding empty lines) | |
730 xnoremap <silent> ai :<c-u>call <sid>aroundIndentation()<cr> | |
731 onoremap <silent> ai :<c-u>call <sid>aroundIndentation()<cr> | |
732 " }}} | |
733 " }}} | |
734 | |
735 " Filetype specific settings {{{ | |
736 " Latex {{{ | |
737 " Open pdf | |
738 | |
739 function! Latexprog() | |
740 if !filereadable("./Makefile") | |
741 setlocal makeprg=latexmk\ -interaction=nonstopmode\ -synctex=1\ -file-line-error\ -pdf\ %:r | |
742 endif | |
743 endfunction | |
744 | |
745 augroup latex | |
746 autocmd! | |
747 autocmd FileType tex call Latexprog() | |
748 au BufNewFile,BufRead,BufEnter *.tex setlocal spell spelllang=en_gb | |
749 au BufNewFile,BufRead,BufEnter *.tex setlocal textwidth=0 | |
750 augroup END | |
751 " }}} | |
752 " Markdown {{{ | |
753 let g:vim_markdown_folding_disabled=1 | |
754 " }}} | |
755 " Text {{{ | |
756 augroup ft_text | |
757 au! | |
758 " au BufNewFile,BufRead,BufEnter *.txt setlocal spell spelllang=en_gb | |
759 au BufNewFile,BufRead,BufEnter *.txt setlocal textwidth=0 | |
760 augroup END | |
761 augroup ft_report | |
762 au! | |
763 au BufNewFile,BufRead,BufEnter *.rpt setlocal nowrap | |
764 au BufNewFile,BufRead,BufEnter *.rpt call ColorRpt() | |
765 au BufNewFile,BufRead,BufEnter *.log call ColorRpt() | |
766 augroup END | |
767 | |
768 function! ColorRpt() | |
769 " Color numbers based on length | |
770 syn match String "\v<\d{1,3}>" | |
771 syn match Number "\v<\d{4,6}>" | |
772 syn match Statement "\v<\d{7,9}>" | |
773 | |
774 " Color errors | |
775 syn match Error "\v^ERROR:.*$" | |
776 endfunction | |
777 " }}} | |
778 " Git commit messages {{{ | |
779 augroup ft_git | |
780 au! | |
781 au FileType gitcommit setlocal spell spelllang=en_gb | |
782 autocmd FileType gitcommit,gitrebase,gitconfig set bufhidden=delete | |
783 augroup END | |
784 " }}} | |
785 " Ruby {{{ | |
786 augroup ft_ruby | |
787 au! | |
788 autocmd BufRead *_spec.rb set filetype=rspec | |
789 augroup END | |
790 " }}} | |
791 " Matlab {{{ | |
792 augroup ft_matlab | |
793 au! | |
794 autocmd FileType matlab setlocal commentstring=\%\ %s | |
795 augroup END | |
796 " }}} | |
797 " C {{{ | |
798 augroup ft_c | |
799 au! | |
800 au FileType c setlocal foldmethod=syntax | |
801 augroup END | |
802 " }}} | |
803 " VHDL {{{ | |
804 " VHDL ctags | |
805 let g:tlist_vhdl_settings = 'vhdl;d:package declarations;b:package bodies;e:entities;a:architecture specifications;t:type declarations;p:processes;f:functions;r:procedures' | |
806 let g:vhdl_indent_genportmap =0 | |
807 let g:vhdl_indent_rhassign = 1 | |
808 | |
809 augroup ft_vhdl | |
810 au! | |
811 autocmd FileType vhdl call VHDLColonAlign() | |
812 augroup END | |
813 | |
814 function! SetAutoAlign() | |
815 inoremap <silent> => =><ESC>mzvip:EasyAlign/=>/<CR>`z$a | |
816 endfunction | |
817 | |
818 function! VHDLChipScopeMacro() | |
819 let @c = "mtyiw'Sosignal \"_cs : std_logic;'Coattribute mark_debug of \"_cs : signal is \"true\"; | |
820 attribute dont_touch of \"_cs : signal is \"true\";'Do\"_cs <= \";=='t" | |
821 endfunction | |
822 | |
823 function! VHDLColonAlign() | |
824 let g:easy_align_delimiters = { | |
825 \ ':': { 'pattern': ':', 'left_margin': 1, 'right_margin': 1, 'stick_to_left': 0} | |
826 \} | |
827 endfunction | |
828 " }}} | |
829 " TCL {{{ | |
830 | |
831 augroup ft_tcl | |
832 au! | |
833 autocmd FileType tcl setlocal commentstring=#\ %s | |
834 " autocmd FileType tcl compiler nagelfar | |
835 autocmd BufRead *.do set filetype=tcl | |
836 autocmd BufRead *.hal set filetype=tcl | |
837 autocmd FileType tcl setlocal iskeyword+=: | |
838 autocmd FileType tcl setlocal breakat-=: | |
839 autocmd FileType tcl setlocal suffixesadd+=.tcl,.do | |
840 augroup END | |
841 " shortcuts | |
842 iabbrev procargs array set arg [::argument_processing::proces_arguments $args]; | |
843 " }}} | |
844 " GPG {{{ | |
845 " Don't save backups of gpg asc files | |
846 set backupskip+=*.asc | |
847 | |
848 " Convenient editing of ascii-armoured encrypted files | |
849 augroup GPGASCII | |
850 au! | |
851 au BufReadPost *.asc :%!gpg -q -d | |
852 au BufReadPost *.asc |redraw | |
853 au BufWritePre *.asc :%!gpg -q -e -a | |
854 au BufWritePost *.asc u | |
855 au VimLeave *.asc :!clear | |
856 augroup END | |
857 " }}} | |
858 " System Verilog {{{ | |
859 augroup ft_systemverilog | |
860 au! | |
861 au FileType systemverilog setlocal suffixesadd+=.sv,.v | |
862 au FileType systemverilog setlocal foldmethod=expr | |
863 au FileType systemverilog setlocal foldexpr=nvim_treesitter#foldexpr() | |
864 au FileType systemverilog,verilog call SVAlign() | |
865 au FileType systemverilog,verilog let b:delimitMate_quotes = "\"" | |
866 au FileType systemverilog,verilog set iskeyword+=' | |
867 augroup END | |
868 | |
869 function! SVAlign() | |
870 let g:easy_align_delimiters = { | |
871 \ ')': { 'pattern': '[()]', 'left_margin': 0, 'right_margin': 0, 'stick_to_left': 0} | |
872 \} | |
873 endfunction | |
874 " }}} | |
875 " Make {{{ | |
876 augroup ft_make | |
877 autocmd! | |
878 autocmd BufEnter *.make setlocal filetype=make | |
879 autocmd FileType make setlocal noexpandtab | |
880 augroup END | |
881 " JSON {{{ | |
882 augroup ft_json | |
883 autocmd! | |
884 autocmd FileType json setlocal equalprg=jq | |
885 augroup END | |
886 " }}} | |
887 " }}} | |
888 " Python {{{ | |
889 augroup f_python | |
890 autocmd! | |
891 autocmd FileType python setlocal shiftwidth=4 | |
892 au FileType python setlocal formatprg=autopep8\ - | |
893 autocmd FileType python setlocal path-=** | |
894 autocmd Filetype python let b:delimitMate_nesting_quotes = ['"', "'"] | |
895 augroup END | |
896 | |
897 let g:python_highlight_all=1 | |
898 " }}} | |
899 " }}} | |
900 | |
901 " Plugin settings {{{ | |
902 " Gundo tree {{{ | |
903 nnoremap <leader>u :GundoToggle<CR> | |
904 " }}} | |
905 " Projectionist {{{ | |
906 let g:projectionist_heuristics = { | |
907 \ "*.c": { | |
908 \ "*.c": { | |
909 \ "alternate": "{}.h", | |
910 \ "type": "source", | |
911 \ "template": ["#include \"{}.h\""], | |
912 \ "make": "make -wC {project}" | |
913 \ }, | |
914 \ "*.h": { | |
915 \ "alternate": "{}.c", | |
916 \ "type": "header", | |
917 \ "template": ["#ifndef {uppercase}_H", "#define {uppercase}_H", "", "#endif"] | |
918 \ }, | |
919 \ "Makefile": {"type": "makefile"}, | |
920 \ }, | |
921 \ "*.py": { | |
922 \ "*.py": { "make": "ipython {}" } | |
923 \ }, | |
924 \ } | |
925 " }}} | |
926 " Grep {{{ | |
927 let g:grepper = { | |
928 \ 'tools': ['ag', 'hg'], | |
929 \ 'highlight': 1, | |
930 \ 'ag': { | |
931 \ 'grepprg': 'rg --vimgrep', | |
932 \ }} | |
933 | |
934 nnoremap gs <plug>(GrepperOperator) | |
935 xnoremap gs <plug>(GrepperOperator) | |
936 | |
937 | |
938 command! -nargs=* -complete=file Ag Grepper -noprompt -tool ag -grepprg rg --vimgrep <args> | |
939 " }}} | |
940 " Vinegar/NetRW {{{ | |
941 autocmd FileType netrw setl bufhidden=delete | |
942 " }}} | |
943 " NCM {{{ | |
944 function! s:check_back_space() abort | |
945 let col = col('.') - 1 | |
946 return !col || getline('.')[col - 1] =~# '\s' | |
947 endfunction | |
948 | |
949 " let g:completion_confirm_key_rhs = "\<Plug>delimitMateCR" | |
950 let g:completion_confirm_key = "" | |
951 imap <expr> <CR> (pumvisible() ? (complete_info()["selected"] != "-1" ? "\<Plug>(completion_confirm_completion)" : "\<Plug>delimitMateCR") : "\<Plug>delimitMateCR") | |
952 | |
953 " Auto close popup menu when finish completion | |
954 autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif | |
955 | |
956 " Use <Tab> and <S-Tab> to navigate through popup menu | |
957 inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>" | |
958 inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>" | |
959 | |
960 " Set completeopt to have a better completion experience | |
961 set completeopt=menuone,noinsert,noselect | |
962 | |
963 " Avoid showing message extra message when using completion | |
964 set shortmess+=c | |
965 | |
966 let g:completion_enable_snippet = 'UltiSnips' | |
967 let g:UltiSnipsJumpForwardTrigger="<c-b>" | |
968 let g:UltiSnipsJumpBackwardTrigger="<c-z>" | |
969 let g:completion_enable_auto_paren=0 | |
970 | |
971 imap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>' | |
972 smap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>' | |
973 imap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>' | |
974 smap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>' | |
975 | |
976 let delimitMate_expand_cr = 1 | |
977 let delimitMate_expand_space = 1 | |
978 " }}} | |
979 " Splice {{{ | |
980 let g:splice_initial_diff_grid=1 | |
981 let g:splice_initial_diff_compare=1 | |
982 let g:splice_initial_diff_path=0 | |
983 let g:splice_initial_scrollbind_grid=1 | |
984 let g:splice_initial_scrollbind_compare=1 | |
985 let g:splice_initial_scrollbind_path=1 | |
986 let g:splice_wrap="nowrap" | |
987 " }}} | |
988 " }}} | |
989 | |
990 function! SendOSCClipboard(lines, regtype) | |
991 call SendViaOSC52(join(a:lines, "\n")) | |
992 endfunction | |
993 | |
994 let g:clipboard = { | |
995 \ 'name': 'TMUX', | |
996 \ 'copy': { | |
997 \ '+': function('SendOSCClipboard'), | |
998 \ '*': 'tmux load-buffer -', | |
999 \ }, | |
1000 \ 'paste': { | |
1001 \ '+': 'tmux save-buffer -', | |
1002 \ '*': 'tmux save-buffer -', | |
1003 \ }, | |
1004 \ 'cache_enabled': 1, | |
1005 \ } | |
1006 " Load local vimrc | |
1007 if filereadable($HOME . '/.vimrc.local') | |
1008 source ~/.vimrc.local | |
1009 endif | |
1010 | |
1011 " Load project local vimrc | |
1012 if filereadable('.vimrc.local') | |
1013 source .vimrc.local | |
1014 endif | |
1015 | |
421
04d84cc8e59a
Automatically apply chezmoi config when saving
zegervdv <zegervdv@me.com>
parents:
411
diff
changeset
|
1016 augroup Chezmoi |
04d84cc8e59a
Automatically apply chezmoi config when saving
zegervdv <zegervdv@me.com>
parents:
411
diff
changeset
|
1017 autocmd! |
04d84cc8e59a
Automatically apply chezmoi config when saving
zegervdv <zegervdv@me.com>
parents:
411
diff
changeset
|
1018 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
|
1019 augroup END |