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