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