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