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