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