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