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