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