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