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