Mercurial > dotfiles
annotate dot_config/nvim/init.vim @ 340:140a585c3393
Enable insert mode when entering a terminal
author | zegervdv <zegervdv@me.com> |
---|---|
date | Sat, 23 Jan 2021 16:39:57 +0100 |
parents | 890fe7d01f19 |
children | 111a00459ad9 |
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 <C-h> <C-\><C-n><C-w>h | |
395 tnoremap <C-j> <C-\><C-n><C-w>j | |
396 tnoremap <C-k> <C-\><C-n><C-w>k | |
397 tnoremap <C-l> <C-\><C-n><C-w>l | |
398 augroup enter_term | |
399 au! | |
340
140a585c3393
Enable insert mode when entering a terminal
zegervdv <zegervdv@me.com>
parents:
338
diff
changeset
|
400 autocmd TermOpen * startinsert! |
140a585c3393
Enable insert mode when entering a terminal
zegervdv <zegervdv@me.com>
parents:
338
diff
changeset
|
401 autocmd BufEnter * if &buftype ==# 'terminal' | :startinsert! | endif |
140a585c3393
Enable insert mode when entering a terminal
zegervdv <zegervdv@me.com>
parents:
338
diff
changeset
|
402 autocmd BufLeave * if &buftype ==# 'terminal' | :stopinsert! | endif |
273 | 403 augroup END |
338
890fe7d01f19
Use toggleterm as more robust terminal integration
zegervdv <zegervdv@me.com>
parents:
329
diff
changeset
|
404 let $GIT_EDITOR = 'nvr -cc split --remote-wait' |
273 | 405 endif |
406 | |
407 " Open buffers, tags... in vertical splits | |
408 nnoremap <leader>b :vert sbuffer | |
409 nnoremap <leader>t :vert stjump | |
410 nnoremap <leader>f :vert sfind | |
411 | |
412 | |
413 " }}} | |
414 | |
415 " Functions {{{ | |
416 " When editing a file, always jump to the last known cursor position. | |
417 " Don't do it for commit messages, when the position is invalid, or when | |
418 " inside an event handler (happens when dropping a file on gvim). | |
419 autocmd BufReadPost * | |
420 \ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") | | |
421 \ exe "normal g`\"" | | |
422 \ endif | |
423 | |
424 " Thg mappings | |
425 function! s:HGhist(file) | |
426 if !empty(a:file) | |
427 let path = a:file | |
428 else | |
429 let path = expand('%') | |
430 endif | |
431 exec 'silent! !thg filelog ' . path . ' &' | |
432 endfunction | |
433 | |
434 command! -nargs=? -complete=file HGhist call s:HGhist(<q-args>) | |
435 | |
436 augroup focus_lost | |
437 au! | |
438 au FocusLost * if !&readonly | :wa | endif | |
439 augroup END | |
440 | |
441 augroup LuaHighlight | |
442 autocmd! | |
443 autocmd TextYankPost * silent! lua require'vim.highlight'.on_yank() | |
444 augroup END | |
445 | |
446 " Resize splits after window resize {{{ | |
447 augroup vim_resize | |
448 au! | |
449 au VimResized * exe "normal! \<c-w>=" | |
450 augroup END | |
451 " }}} | |
452 | |
453 " Automatically reload vimrc when saving {{{ | |
454 augroup reload_vim | |
455 autocmd! | |
456 autocmd BufWritePost $MYVIMRC nested source $MYVIMRC | |
457 augroup END | |
458 " }}} | |
459 | |
460 " Reload diffs {{{ | |
461 augroup diff_files | |
462 au! | |
463 au BufWritePost * if &diff == 1 | diffupdate | endif | |
464 augroup END | |
465 " }}} | |
466 | |
467 " Custom folding by Steve Losh | |
468 function! MyFoldText() " {{{ | |
469 let line = getline(v:foldstart) | |
470 | |
471 let nucolwidth = &fdc + &number * &numberwidth | |
472 let windowwidth = winwidth(0) - nucolwidth - 3 | |
473 let foldedlinecount = v:foldend - v:foldstart | |
474 | |
475 " expand tabs into spaces | |
476 let onetab = strpart(' ', 0, &tabstop) | |
477 let line = substitute(line, '\t', onetab, 'g') | |
478 | |
479 let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount)) | |
480 let fillcharcount = windowwidth - len(line) - len(foldedlinecount) | |
481 return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' ' | |
482 endfunction " }}} | |
483 set foldtext=MyFoldText() | |
484 set foldopen+=jump | |
485 | |
486 " Detect Filetype from content if file has no extension {{{ | |
487 augroup newFileDetection | |
488 au! | |
489 autocmd CursorMovedI * call CheckFileType() | |
490 augroup END | |
491 | |
492 function! CheckFileType() | |
493 if exists("b:countCheck") == 0 | |
494 let b:countCheck = 0 | |
495 endif | |
496 let b:countCheck += 1 | |
497 if &filetype == "" && b:countCheck > 20 && b:countCheck < 200 | |
498 filetype detect | |
499 " Delete the function if no filetype can be established, or the type has | |
500 " been found | |
501 elseif b:countCheck >= 200 || &filetype != "" | |
502 autocmd! newFileDetection | |
503 endif | |
504 endfunction | |
505 " }}} | |
506 | |
507 " Convert hex <-> decimal {{{ | |
508 command! -nargs=? -range Dec2hex call s:Dec2hex(<line1>, <line2>, '<args>') | |
509 function! s:Dec2hex(line1, line2, arg) range | |
510 if empty(a:arg) | |
511 if histget(':', -1) =~# "^'<,'>" && visualmode() !=# 'V' | |
512 let cmd = 's/\%V\<\d\+\>/\=printf("0x%x",submatch(0)+0)/g' | |
513 else | |
514 let cmd = 's/\<\d\+\>/\=printf("0x%x",submatch(0)+0)/g' | |
515 endif | |
516 try | |
517 execute a:line1 . ',' . a:line2 . cmd | |
518 catch | |
519 echo 'Error: No decimal number found' | |
520 endtry | |
521 else | |
522 echo printf('%x', a:arg + 0) | |
523 endif | |
524 endfunction | |
525 | |
526 command! -nargs=? -range Hex2dec call s:Hex2dec(<line1>, <line2>, '<args>') | |
527 function! s:Hex2dec(line1, line2, arg) range | |
528 if empty(a:arg) | |
529 if histget(':', -1) =~# "^'<,'>" && visualmode() !=# 'V' | |
530 let cmd = 's/\%V0x\x\+/\=submatch(0)+0/g' | |
531 else | |
532 let cmd = 's/0x\x\+/\=submatch(0)+0/g' | |
533 endif | |
534 try | |
535 execute a:line1 . ',' . a:line2 . cmd | |
536 catch | |
537 echo 'Error: No hex number starting "0x" found' | |
538 endtry | |
539 else | |
540 echo (a:arg =~? '^0x') ? a:arg + 0 : ('0x'.a:arg) + 0 | |
541 endif | |
542 endfunction | |
543 " }}} | |
544 | |
545 " Recognize filetype for dup files {{{ | |
546 autocmd! BufRead *.dup call DupSetSyntax(@%) | |
547 | |
548 function! DupSetSyntax(name) | |
549 let extension = matchlist(a:name, '\v.+.\.([^\.]+).dup')[1] | |
550 if extension == "vhd" | |
551 setlocal filetype=vhdl | |
552 elseif extension == "v" | |
553 setlocal filetype=verilog | |
554 elseif extension == "sv" | |
555 setlocal filetype=verilog | |
556 else | |
557 echo "Unknown filetype" | |
558 endif | |
559 endfunction | |
560 " }}} | |
561 | |
562 " Create arguments list from files in quickfix list | |
563 " Allows to Grep for a pattern and apply an argdo command on each of the | |
564 " matching files {{{ | |
565 command! -nargs=0 -bar Qargs execute 'args' QuickfixFilenames() | |
566 function! QuickfixFilenames() | |
567 " Building a hash ensures we get each buffer only once | |
568 let buffer_numbers = {} | |
569 for quickfix_item in getqflist() | |
570 let buffer_numbers[quickfix_item['bufnr']] = bufname(quickfix_item['bufnr']) | |
571 endfor | |
572 return join(map(values(buffer_numbers), 'fnameescape(v:val)')) | |
573 endfunction | |
574 "}}} | |
575 | |
576 augroup mark_files | |
577 au! | |
578 au BufLeave test.tcl mark T | |
579 au BufLeave case.do mark C | |
580 au BufLeave drv_*.tcl mark D | |
581 au BufLeave *.rtl.vhd mark R | |
582 augroup END | |
583 | |
584 | |
585 " Toggle between opening/closing the quickfix window {{{ | |
586 function! GetBufferList() | |
587 redir =>buflist | |
588 silent! ls! | |
589 redir END | |
590 return buflist | |
591 endfunction | |
592 | |
593 function! ToggleList(bufname, pfx) | |
594 let buflist = GetBufferList() | |
595 for bufnum in map(filter(split(buflist, '\n'), 'v:val =~ "'.a:bufname.'"'), 'str2nr(matchstr(v:val, "\\d\\+"))') | |
596 if bufwinnr(bufnum) != -1 | |
597 exec(a:pfx.'close') | |
598 return | |
599 endif | |
600 endfor | |
601 if a:pfx == 'l' && len(getloclist(0)) == 0 | |
602 echohl ErrorMsg | |
603 echo "Location List is Empty." | |
604 return | |
605 endif | |
606 let winnr = winnr() | |
607 exec('botright '.a:pfx.'open') | |
608 if winnr() != winnr | |
609 wincmd p | |
610 endif | |
611 endfunction | |
612 | |
613 nnoremap <silent> <F10> :call ToggleList("Quickfix List", 'c')<CR> | |
614 " }}} | |
615 | |
616 | |
617 " Make list-like commands more intuitive {{{ | |
618 " Copied from https://gist.github.com/romainl/047aca21e338df7ccf771f96858edb86 | |
619 function! CCR() | |
620 let cmdline = getcmdline() | |
621 if cmdline =~ '\v\C^(ls|files|buffers)' | |
622 " like :ls but prompts for a buffer command | |
623 return "\<CR>:b" | |
624 elseif cmdline =~ '\v\C/(#|nu|num|numb|numbe|number)$' | |
625 " like :g//# but prompts for a command | |
626 return "\<CR>:" | |
627 elseif cmdline =~ '\v\C^(dli|il)' | |
628 " like :dlist or :ilist but prompts for a count for :djump or :ijump | |
629 return "\<CR>:" . cmdline[0] . "j " . split(cmdline, " ")[1] . "\<S-Left>\<Left>" | |
630 elseif cmdline =~ '\v\C^(cli|lli)' | |
631 " like :clist or :llist but prompts for an error/location number | |
632 return "\<CR>:sil " . repeat(cmdline[0], 2) . "\<Space>" | |
633 elseif cmdline =~ '\C^old' | |
634 " like :oldfiles but prompts for an old file to edit | |
635 set nomore | |
636 return "\<CR>:sil se more|e #<" | |
637 elseif cmdline =~ '\C^changes' | |
638 " like :changes but prompts for a change to jump to | |
639 set nomore | |
640 return "\<CR>:sil se more|norm! g;\<S-Left>" | |
641 elseif cmdline =~ '\C^ju' | |
642 " like :jumps but prompts for a position to jump to | |
643 set nomore | |
644 return "\<CR>:sil se more|norm! \<C-o>\<S-Left>" | |
645 elseif cmdline =~ '\C^marks' | |
646 " like :marks but prompts for a mark to jump to | |
647 return "\<CR>:norm! `" | |
648 elseif cmdline =~ '\C^undol' | |
649 " like :undolist but prompts for a change to undo | |
650 return "\<CR>:u " | |
651 else | |
652 return "\<CR>" | |
653 endif | |
654 endfunction | |
655 cnoremap <expr> <CR> CCR() | |
656 " }}} | |
657 | |
658 " Text objects {{{ | |
659 function! s:inIndentation() | |
660 " select all text in current indentation level excluding any empty lines | |
661 " that precede or follow the current indentationt level; | |
662 " | |
663 " the current implementation is pretty fast, even for many lines since it | |
664 " uses "search()" with "\%v" to find the unindented levels | |
665 " | |
666 " NOTE: if the current level of indentation is 1 (ie in virtual column 1), | |
667 " then the entire buffer will be selected | |
668 " | |
669 " WARNING: python devs have been known to become addicted to this | |
670 " magic is needed for this | |
671 let l:magic = &magic | |
672 set magic | |
673 | |
674 " move to beginning of line and get virtcol (current indentation level) | |
675 " BRAM: there is no searchpairvirtpos() ;) | |
676 normal! ^ | |
677 let l:vCol = virtcol(getline('.') =~# '^\s*$' ? '$' : '.') | |
678 | |
679 " pattern matching anything except empty lines and lines with recorded | |
680 " indentation level | |
681 let l:pat = '^\(\s*\%'.l:vCol.'v\|^$\)\@!' | |
682 | |
683 " find first match (backwards & don't wrap or move cursor) | |
684 let l:start = search(l:pat, 'bWn') + 1 | |
685 | |
686 " next, find first match (forwards & don't wrap or move cursor) | |
687 let l:end = search(l:pat, 'Wn') | |
688 | |
689 if (l:end !=# 0) | |
690 " if search succeeded, it went too far, so subtract 1 | |
691 let l:end -= 1 | |
692 endif | |
693 | |
694 " go to start (this includes empty lines) and--importantly--column 0 | |
695 execute 'normal! '.l:start.'G0' | |
696 | |
697 " skip empty lines (unless already on one .. need to be in column 0) | |
698 call search('^[^\n\r]', 'Wc') | |
699 | |
700 " go to end (this includes empty lines) | |
701 execute 'normal! Vo'.l:end.'G' | |
702 | |
703 " skip backwards to last selected non-empty line | |
704 call search('^[^\n\r]', 'bWc') | |
705 | |
706 " go to end-of-line 'cause why not | |
707 normal! $o | |
708 | |
709 " restore magic | |
710 let &magic = l:magic | |
711 endfunction | |
712 | |
713 " "in indentation" (indentation level sans any surrounding empty lines) | |
714 xnoremap <silent> ii :<c-u>call <sid>inIndentation()<cr> | |
715 onoremap <silent> ii :<c-u>call <sid>inIndentation()<cr> | |
716 | |
717 function! s:aroundIndentation() | |
718 " select all text in the current indentation level including any emtpy | |
719 " lines that precede or follow the current indentation level; | |
720 " | |
721 " the current implementation is pretty fast, even for many lines since it | |
722 " uses "search()" with "\%v" to find the unindented levels | |
723 " | |
724 " NOTE: if the current level of indentation is 1 (ie in virtual column 1), | |
725 " then the entire buffer will be selected | |
726 " | |
727 " WARNING: python devs have been known to become addicted to this | |
728 | |
729 " magic is needed for this (/\v doesn't seem work) | |
730 let l:magic = &magic | |
731 set magic | |
732 | |
733 " move to beginning of line and get virtcol (current indentation level) | |
734 " BRAM: there is no searchpairvirtpos() ;) | |
735 normal! ^ | |
736 let l:vCol = virtcol(getline('.') =~# '^\s*$' ? '$' : '.') | |
737 | |
738 " pattern matching anything except empty lines and lines with recorded | |
739 " indentation level | |
740 let l:pat = '^\(\s*\%'.l:vCol.'v\|^$\)\@!' | |
741 | |
742 " find first match (backwards & don't wrap or move cursor) | |
743 let l:start = search(l:pat, 'bWn') + 1 | |
744 | |
745 " NOTE: if l:start is 0, then search() failed; otherwise search() succeeded | |
746 " and l:start does not equal line('.') | |
747 " FORMER: l:start is 0; so, if we add 1 to l:start, then it will match | |
748 " everything from beginning of the buffer (if you don't like | |
749 " this, then you can modify the code) since this will be the | |
750 " equivalent of "norm! 1G" below | |
751 " LATTER: l:start is not 0 but is also not equal to line('.'); therefore, | |
752 " we want to add one to l:start since it will always match one | |
753 " line too high if search() succeeds | |
754 | |
755 " next, find first match (forwards & don't wrap or move cursor) | |
756 let l:end = search(l:pat, 'Wn') | |
757 | |
758 " NOTE: if l:end is 0, then search() failed; otherwise, if l:end is not | |
759 " equal to line('.'), then the search succeeded. | |
760 " FORMER: l:end is 0; we want this to match until the end-of-buffer if it | |
761 " fails to find a match for same reason as mentioned above; | |
762 " again, modify code if you do not like this); therefore, keep | |
763 " 0--see "NOTE:" below inside the if block comment | |
764 " LATTER: l:end is not 0, so the search() must have succeeded, which means | |
765 " that l:end will match a different line than line('.') | |
766 | |
767 if (l:end !=# 0) | |
768 " if l:end is 0, then the search() failed; if we subtract 1, then it | |
769 " will effectively do "norm! -1G" which is definitely not what is | |
770 " desired for probably every circumstance; therefore, only subtract one | |
771 " if the search() succeeded since this means that it will match at least | |
772 " one line too far down | |
773 " NOTE: exec "norm! 0G" still goes to end-of-buffer just like "norm! G", | |
774 " so it's ok if l:end is kept as 0. As mentioned above, this means | |
775 " that it will match until end of buffer, but that is what I want | |
776 " anyway (change code if you don't want) | |
777 let l:end -= 1 | |
778 endif | |
779 | |
780 " finally, select from l:start to l:end | |
781 execute 'normal! '.l:start.'G0V'.l:end.'G$o' | |
782 | |
783 " restore magic | |
784 let &magic = l:magic | |
785 endfunction | |
786 | |
787 " "around indentation" (indentation level and any surrounding empty lines) | |
788 xnoremap <silent> ai :<c-u>call <sid>aroundIndentation()<cr> | |
789 onoremap <silent> ai :<c-u>call <sid>aroundIndentation()<cr> | |
790 " }}} | |
791 " }}} | |
792 | |
793 " Filetype specific settings {{{ | |
794 " Latex {{{ | |
795 " Open pdf | |
796 | |
797 function! Latexprog() | |
798 if !filereadable("./Makefile") | |
799 setlocal makeprg=latexmk\ -interaction=nonstopmode\ -synctex=1\ -file-line-error\ -pdf\ %:r | |
800 endif | |
801 endfunction | |
802 | |
803 augroup latex | |
804 autocmd! | |
805 autocmd FileType tex call Latexprog() | |
806 au BufNewFile,BufRead,BufEnter *.tex setlocal spell spelllang=en_gb | |
807 au BufNewFile,BufRead,BufEnter *.tex setlocal textwidth=0 | |
808 augroup END | |
809 " }}} | |
810 " Markdown {{{ | |
811 let g:vim_markdown_folding_disabled=1 | |
812 " }}} | |
813 " Text {{{ | |
814 augroup ft_text | |
815 au! | |
816 " au BufNewFile,BufRead,BufEnter *.txt setlocal spell spelllang=en_gb | |
817 au BufNewFile,BufRead,BufEnter *.txt setlocal textwidth=0 | |
818 augroup END | |
819 augroup ft_report | |
820 au! | |
821 au BufNewFile,BufRead,BufEnter *.rpt setlocal nowrap | |
822 au BufNewFile,BufRead,BufEnter *.rpt call ColorRpt() | |
823 au BufNewFile,BufRead,BufEnter *.log call ColorRpt() | |
824 augroup END | |
825 | |
826 function! ColorRpt() | |
827 " Color numbers based on length | |
828 syn match String "\v<\d{1,3}>" | |
829 syn match Number "\v<\d{4,6}>" | |
830 syn match Statement "\v<\d{7,9}>" | |
831 | |
832 " Color errors | |
833 syn match Error "\v^ERROR:.*$" | |
834 endfunction | |
835 " }}} | |
836 " Git commit messages {{{ | |
837 augroup ft_git | |
838 au! | |
839 au FileType gitcommit setlocal spell spelllang=en_gb | |
840 augroup END | |
841 " }}} | |
842 " Ruby {{{ | |
843 augroup ft_ruby | |
844 au! | |
845 autocmd BufRead *_spec.rb set filetype=rspec | |
846 augroup END | |
847 " }}} | |
848 " Matlab {{{ | |
849 augroup ft_matlab | |
850 au! | |
851 autocmd FileType matlab setlocal commentstring=\%\ %s | |
852 augroup END | |
853 " }}} | |
854 " C {{{ | |
855 augroup ft_c | |
856 au! | |
857 au FileType c setlocal foldmethod=syntax | |
858 augroup END | |
859 " }}} | |
860 " VHDL {{{ | |
861 " VHDL ctags | |
862 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' | |
863 let g:vhdl_indent_genportmap =0 | |
864 let g:vhdl_indent_rhassign = 1 | |
865 | |
866 augroup ft_vhdl | |
867 au! | |
868 autocmd FileType vhdl call VHDLColonAlign() | |
869 augroup END | |
870 | |
871 function! SetAutoAlign() | |
872 inoremap <silent> => =><ESC>mzvip:EasyAlign/=>/<CR>`z$a | |
873 endfunction | |
874 | |
875 function! VHDLChipScopeMacro() | |
876 let @c = "mtyiw'Sosignal \"_cs : std_logic;'Coattribute mark_debug of \"_cs : signal is \"true\"; | |
877 attribute dont_touch of \"_cs : signal is \"true\";'Do\"_cs <= \";=='t" | |
878 endfunction | |
879 | |
880 function! VHDLColonAlign() | |
881 let g:easy_align_delimiters = { | |
882 \ ':': { 'pattern': ':', 'left_margin': 1, 'right_margin': 1, 'stick_to_left': 0} | |
883 \} | |
884 endfunction | |
885 " }}} | |
886 " TCL {{{ | |
887 | |
888 augroup ft_tcl | |
889 au! | |
890 autocmd FileType tcl setlocal commentstring=#\ %s | |
891 " autocmd FileType tcl compiler nagelfar | |
892 autocmd BufRead *.do set filetype=tcl | |
893 autocmd BufRead *.hal set filetype=tcl | |
894 autocmd FileType tcl setlocal iskeyword+=: | |
895 autocmd FileType tcl setlocal breakat-=: | |
896 autocmd FileType tcl setlocal suffixesadd+=.tcl,.do | |
897 augroup END | |
898 " shortcuts | |
899 iabbrev procargs array set arg [::argument_processing::proces_arguments $args]; | |
900 " }}} | |
901 " GPG {{{ | |
902 " Don't save backups of gpg asc files | |
903 set backupskip+=*.asc | |
904 | |
905 " Convenient editing of ascii-armoured encrypted files | |
906 augroup GPGASCII | |
907 au! | |
908 au BufReadPost *.asc :%!gpg -q -d | |
909 au BufReadPost *.asc |redraw | |
910 au BufWritePre *.asc :%!gpg -q -e -a | |
911 au BufWritePost *.asc u | |
912 au VimLeave *.asc :!clear | |
913 augroup END | |
914 " }}} | |
915 " System Verilog {{{ | |
916 augroup ft_systemverilog | |
917 au! | |
918 au FileType systemverilog setlocal suffixesadd+=.sv,.v | |
305
10078cb76622
Add treesitter refactor and textobjects plugins
zegervdv <zegervdv@me.com>
parents:
303
diff
changeset
|
919 au FileType systemverilog setlocal foldmethod=expr |
10078cb76622
Add treesitter refactor and textobjects plugins
zegervdv <zegervdv@me.com>
parents:
303
diff
changeset
|
920 au FileType systemverilog setlocal foldexpr=nvim_treesitter#foldexpr() |
273 | 921 au FileType systemverilog,verilog call SVAlign() |
276
ecc3074ac1fc
Add delimitMate config for systemverilog and python
zegervdv <zegervdv@me.com>
parents:
275
diff
changeset
|
922 au FileType systemverilog,verilog let b:delimitMate_quotes = "\"" |
273 | 923 augroup END |
924 | |
925 function! SVAlign() | |
926 let g:easy_align_delimiters = { | |
927 \ ')': { 'pattern': '[()]', 'left_margin': 0, 'right_margin': 0, 'stick_to_left': 0} | |
928 \} | |
929 endfunction | |
930 " }}} | |
931 " Make {{{ | |
932 augroup ft_make | |
933 autocmd! | |
934 autocmd BufEnter *.make setlocal filetype=make | |
935 autocmd FileType make setlocal noexpandtab | |
936 augroup END | |
937 " JSON {{{ | |
938 augroup ft_json | |
939 autocmd! | |
940 autocmd FileType json setlocal equalprg=jq | |
941 augroup END | |
942 " }}} | |
943 " }}} | |
944 " Python {{{ | |
945 augroup f_python | |
946 autocmd! | |
947 autocmd FileType python setlocal shiftwidth=4 | |
948 au FileType python setlocal formatprg=autopep8\ - | |
949 autocmd FileType python setlocal path-=** | |
276
ecc3074ac1fc
Add delimitMate config for systemverilog and python
zegervdv <zegervdv@me.com>
parents:
275
diff
changeset
|
950 autocmd Filetype python let b:delimitMate_nesting_quotes = ['"', "'"] |
273 | 951 augroup END |
952 | |
953 let g:python_highlight_all=1 | |
954 " }}} | |
955 " }}} | |
956 | |
957 " Plugin settings {{{ | |
958 " Easy-align {{{ | |
959 " Start interactive EasyAlign in visual mode (e.g. vip<Enter>) | |
960 vmap <Enter> <Plug>(EasyAlign) | |
961 | |
962 " Start interactive EasyAlign for a motion/text object (e.g. gaip) | |
963 nmap ga <Plug>(EasyAlign) | |
964 " }}} | |
965 " Gundo tree {{{ | |
966 nnoremap <leader>u :GundoToggle<CR> | |
967 " }}} | |
968 " Projectionist {{{ | |
969 let g:projectionist_heuristics = { | |
970 \ "*.c": { | |
971 \ "*.c": { | |
972 \ "alternate": "{}.h", | |
973 \ "type": "source", | |
974 \ "template": ["#include \"{}.h\""], | |
975 \ "make": "make -wC {project}" | |
976 \ }, | |
977 \ "*.h": { | |
978 \ "alternate": "{}.c", | |
979 \ "type": "header", | |
980 \ "template": ["#ifndef {uppercase}_H", "#define {uppercase}_H", "", "#endif"] | |
981 \ }, | |
982 \ "Makefile": {"type": "makefile"}, | |
983 \ }, | |
984 \ "*.py": { | |
985 \ "*.py": { "make": "ipython {}" } | |
986 \ }, | |
987 \ } | |
988 " }}} | |
989 " Grep {{{ | |
990 let g:grepper = { | |
991 \ 'tools': ['ag', 'hg'], | |
992 \ 'highlight': 1, | |
993 \ 'ag': { | |
994 \ 'grepprg': 'rg --vimgrep', | |
995 \ }} | |
996 | |
997 nnoremap gs <plug>(GrepperOperator) | |
998 xnoremap gs <plug>(GrepperOperator) | |
999 | |
1000 | |
1001 command! -nargs=* -complete=file Ag Grepper -noprompt -tool ag -grepprg rg --vimgrep <args> | |
1002 " }}} | |
1003 " Vinegar/NetRW {{{ | |
1004 autocmd FileType netrw setl bufhidden=delete | |
1005 " }}} | |
1006 " NCM {{{ | |
1007 function! s:check_back_space() abort | |
1008 let col = col('.') - 1 | |
1009 return !col || getline('.')[col - 1] =~# '\s' | |
1010 endfunction | |
1011 | |
329
111f178824b9
Fix delimitMate expansion of CR for completion results
Zeger Van de Vannet <zegervdv@me.com>
parents:
327
diff
changeset
|
1012 " 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
|
1013 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
|
1014 imap <expr> <CR> (pumvisible() ? (complete_info()["selected"] != "-1" ? "\<Plug>(completion_confirm_completion)" : "\<Plug>delimitMateCR") : "\<Plug>delimitMateCR") |
273 | 1015 |
1016 " Auto close popup menu when finish completion | |
1017 autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif | |
284 | 1018 |
1019 " Use <Tab> and <S-Tab> to navigate through popup menu | |
1020 inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>" | |
1021 inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>" | |
1022 | |
1023 " Set completeopt to have a better completion experience | |
1024 set completeopt=menuone,noinsert,noselect | |
1025 | |
1026 " Avoid showing message extra message when using completion | |
1027 set shortmess+=c | |
273 | 1028 |
1029 let g:completion_enable_snippet = 'UltiSnips' | |
1030 let g:UltiSnipsJumpForwardTrigger="<c-b>" | |
1031 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
|
1032 let g:completion_enable_auto_paren=0 |
276
ecc3074ac1fc
Add delimitMate config for systemverilog and python
zegervdv <zegervdv@me.com>
parents:
275
diff
changeset
|
1033 |
ecc3074ac1fc
Add delimitMate config for systemverilog and python
zegervdv <zegervdv@me.com>
parents:
275
diff
changeset
|
1034 let delimitMate_expand_cr = 1 |
ecc3074ac1fc
Add delimitMate config for systemverilog and python
zegervdv <zegervdv@me.com>
parents:
275
diff
changeset
|
1035 let delimitMate_expand_space = 1 |
273 | 1036 " }}} |
1037 " Background make {{{ | |
1038 nnoremap <F9> :PMake<CR> | |
1039 " }}} | |
1040 " Splice {{{ | |
1041 let g:splice_initial_diff_grid=1 | |
1042 let g:splice_initial_diff_compare=1 | |
1043 let g:splice_initial_diff_path=0 | |
1044 let g:splice_initial_scrollbind_grid=1 | |
1045 let g:splice_initial_scrollbind_compare=1 | |
1046 let g:splice_initial_scrollbind_path=1 | |
1047 let g:splice_wrap="nowrap" | |
1048 " }}} | |
1049 " Chipscoper {{{ | |
1050 nnoremap <leader>cm :call ChipScoperMark()<CR> | |
1051 nnoremap <leader>ci :call ChipScoperInsert()<CR> | |
1052 nnoremap <leader>cd :call ChipScoperUnMark()<CR> | |
1053 augroup cs_vhdl | |
1054 autocmd! | |
1055 autocmd FileType vhdl packadd chipscoper | |
1056 autocmd FileType vhdl silent! call ChipScoperSetup() | |
1057 augroup END | |
1058 " }}} | |
1059 " GDB {{{ | |
1060 let g:nvimgdb_disable_start_keymaps = 1 | |
1061 " }}} | |
296 | 1062 " Indents {{{ |
1063 let g:indentLine_char = '|' | |
1064 " }}} | |
273 | 1065 " }}} |
1066 | |
1067 function! SendOSCClipboard(lines, regtype) | |
1068 call SendViaOSC52(join(a:lines, "\n")) | |
1069 endfunction | |
1070 | |
1071 let g:clipboard = { | |
1072 \ 'name': 'TMUX', | |
1073 \ 'copy': { | |
1074 \ '+': function('SendOSCClipboard'), | |
1075 \ '*': 'tmux load-buffer -', | |
1076 \ }, | |
1077 \ 'paste': { | |
1078 \ '+': 'tmux save-buffer -', | |
1079 \ '*': 'tmux save-buffer -', | |
1080 \ }, | |
1081 \ 'cache_enabled': 1, | |
1082 \ } | |
1083 " Load local vimrc | |
1084 if filereadable($HOME . '/.vimrc.local') | |
1085 source ~/.vimrc.local | |
1086 endif | |
1087 | |
1088 " Load project local vimrc | |
1089 if filereadable('.vimrc.local') | |
1090 source .vimrc.local | |
1091 endif | |
282 | 1092 |