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