-
Notifications
You must be signed in to change notification settings - Fork 5
/
.vimrc
965 lines (838 loc) · 31.2 KB
/
.vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
" ======================== Vundle Config =================
" _ __ __ __
" ____ _(_) /_/ /_ __ __/ /_
" / __ `/ / __/ __ \/ / / / __ \
" / /_/ / / /_/ / / / /_/ / /_/ /
" \__, /_/\__/_/ /_/\__,_/_.___/
"/____/ ----- Vim Bundles -------
"
set nocompatible " Required
call plug#begin('~/.vim/plugged')
Plug 'airblade/vim-gitgutter'
Plug 'benekastah/neomake'
Plug 'bling/vim-airline'
Plug 'ekalinin/Dockerfile.vim'
Plug 'Ivo-Donchev/vim-react-goto-definition'
Plug 'MunifTanjim/nui.nvim'
Plug 'SirVer/ultisnips'
Plug 'ThePrimeagen/harpoon', { 'branch': 'harpoon2' }
Plug 'ellisonleao/gruvbox.nvim'
Plug 'fatih/vim-go', { 'tag': '*' }
Plug 'folke/tokyonight.nvim', { 'branch': 'main' }
Plug 'gagoar/StripWhiteSpaces'
Plug 'honza/vim-snippets'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/nvim-cmp'
Plug 'jacoborus/tender.vim'
Plug 'jose-elias-alvarez/null-ls.nvim'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'leafgarland/typescript-vim'
Plug 'lilydjwg/colorizer'
Plug 'lucidph3nx/nvim-sops'
Plug 'ludovicchabant/vim-gutentags'
Plug 'majutsushi/tagbar'
Plug 'mbbill/undotree'
Plug 'mustache/vim-mustache-handlebars'
Plug 'neovim/nvim-lspconfig', { 'do': 'npm i -g pyright' }
Plug 'nvim-lua/lsp-status.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " We recommend updating the parsers on update
Plug 'pangloss/vim-javascript'
Plug 'pearofducks/ansible-vim'
Plug 'pedrohdz/vim-yaml-folds'
Plug 'peitalin/vim-jsx-typescript'
Plug 'powerman/vim-plugin-AnsiEsc'
Plug 'prettier/vim-prettier', { 'do': 'yarn install --no-lockfile' }
Plug 'quangnguyen30192/cmp-nvim-ultisnips'
Plug 'sbdchd/neoformat'
Plug 'seanthomaswilliams/dwm.vim'
Plug 'seanthomaswilliams/markdown-preview.nvim', { 'do': 'cd app && yarn install' }
Plug 'shmup/vim-sql-syntax'
Plug 'towolf/vim-helm'
Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'vim-perl/vim-perl'
Plug 'vimwiki/vimwiki'
Plug 'will133/vim-dirdiff'
Plug 'zbirenbaum/copilot-cmp'
Plug 'zbirenbaum/copilot.lua'
" Required, plugins available after.
call plug#end()
lua require('init')
"+----------------- Basic Configurations ------------+
" GUI Configuration
if has('gui_running')
set guioptions-=T
set guioptions+=LlRrb "Some kind of hack for scrollbars
set guioptions-=LlRrb
set guifont=Terminus\ 10
endif
" Commenting blocks of code.
let b:comment_leader = '# '
autocmd FileType c,cpp,go,java,scala let b:comment_leader = '// '
autocmd FileType tex let b:comment_leader = '% '
autocmd FileType sql,lua let b:comment_leader = '-- '
autocmd FileType mail let b:comment_leader = '> '
autocmd FileType vim let b:comment_leader = '" '
" Comment and uncomment
noremap <silent> <leader>C :<C-B>silent <C-E>s/^/<C-R>=escape(b:comment_leader,'\/')<CR>/<CR>:nohlsearch<CR>
noremap <silent> <leader>c :<C-B>silent <C-E>s/^\V<C-R>=escape(b:comment_leader,'\/')<CR>//e<CR>:nohlsearch<CR>
" Vim-Script Configurations
let g:indent_guides_guide_size = 1 " Only use one column to show indent
let g:indent_guides_start_level = 2 " Start on the second level o
" Keymappings
" Quick write, write quit and quit key mappings for normal mode
nmap <leader>wq :write <bar> :quit<CR>
nmap <leader>q :quit<CR>
" Reload current file
nmap <leader>re :e! %<CR>
" Location list mappings
nmap <silent><leader>lc :lcl<CR>
nmap <silent><leader>lo :lw<CR>
" Quick search and replace
nmap S :%s//g<LEFT><LEFT>
" Quick copen/cclose
nnoremap <silent> <leader>c :cclose<CR>
nnoremap <silent> <leader>C :copen<CR>
" Map hotkey for make
nnoremap <silent> <leader>m :make<CR><C-w><Up>
" Make sure shebang-scripts can be run
if !exists('*MakeScriptExecuteable')
function MakeScriptExecuteable()
if getline(1) =~ "^#!.*/bin/"
silent !chmod +x %:p
endif
endfunction
endif
" Don't lose selection when shifting text in visual or select mode
xnoremap < <gv
xnoremap > >gv
" Like gJ, but always remove spaces
fun! s:join_spaceless()
execute 'normal! gJ'
" Remove character under the cursor if it's whitespace.
if matchstr(getline('.'), '\%' . col('.') . 'c.') =~ '\s'
echom "Removing whitespace"
execute 'normal! dw'
else
echom "Not Removing whitespace"
endif
endfun
nnoremap J :verbose call <SID>join_spaceless()<CR>
nnoremap H J
" ARROW KEYS ARE UNACCEPTABLE
map <Left> <Nop>
map <Right> <Nop>
map <Up> <Nop>
map <Down> <Nop>
map <Esc>[B <Down>
" If there is a vimrc.local source that before current
if filereadable(expand("~/.vimrc.local"))
source ~/.vimrc.local
endif
" Edit vimrc configuration file
nnoremap <Leader>ve :e $MYVIMRC<CR>
" Reload vimrc configuration file
nnoremap <Leader>vr :source $MYVIMRC<CR>
" Run PlugInstall after reload
nnoremap <Leader>pi :source $MYVIMRC<CR>:PlugInstall<CR>
" Show neovim health
nnoremap <Leader>ch :checkhealth<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" BASIC EDITING CONFIGURATION
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" {{{ file management options
set autoread " Automatically reread changed files without asking me anything
set autowrite " Automatically save before :next, :make etc.
set undolevels=1000 " How many undos
set undoreload=10000 " number of lines to save for undo
set undodir=~/.vim/tmp/undo// " undo files
set undofile " Save undo's after file closes
set backup " Store temporary files in a central spot
set backupdir=~/.vim/tmp/backup// " backups
set directory=~/.vim/tmp/swap// " swap files
set fileformats=unix,dos,mac " Prefer Unix over Windows over OS 9 formats
set history=10000 " Command history
set noswapfile " it's 2013, Vim.
set tags=./.tags " Look for tags in this file
" }}}
" {{{ colorscheme/style options
colorscheme tokyonight-storm
let g:airline_theme = 'tender'
" Enable true color
if exists('+termguicolors')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors " Enables truecolor in neovim >= 0.1.5
endif
set number " Displays line numbers
set colorcolumn=+1 " highlight column after 'textwidth'
set novisualbell
set errorbells
set cursorline " Show highlight on the cursor line
"set showbreak=↪
set background=dark
set bg=dark
let mapleader="\\"
" Make syntax errors in SCREAM
" (otherwise a missing comma in JSON is bold red vs regular red - not visible)
" :highlight Error term=reverse cterm=bold ctermfg=7 ctermbg=1 guifg=White guibg=Red
" }}}
" {{{ Misc UI settings
set encoding=utf-8
scriptencoding utf-8
set pastetoggle=<F4>
set shell=bash " This makes RVM work inside Vim. I have no idea why.
set showcmd " display incomplete commands
set splitbelow " Split horizontal windows below to the current windows
set splitright " Split vertical windows right to the current windows
set switchbuf=useopen
set synmaxcol=500 " Don't try to highlight lines longer than X characters.
set cmdheight=1
set laststatus=2 " Always have a status line regardless
set modeline
set modelines=5
set numberwidth=5
set mouse=a " Enable mouse in console mode
set noshelltemp " Be a bit faster when executing command-line shell stuff
set hidden " hide open buffers instead of closing them, when opening a new one with :e
set shortmess=actI " Deactivate the PRESS ENTER OR TYPE COMMAND TO CONTINUE message
set clipboard=unnamed " Allows copy-pasting from other apps
set scrolloff=3 " keep moreiabbrev lmis ಠ‿ಠearch matches in the middle of the window.
set redrawtime=10000 " time in ms for redrawing the display (default 2000)
set sidescrolloff=1 " Add some space around the cursor when moving it near the borders of the screen
set lazyredraw " Don't update screen during macro and script execution
set winminheight=0
set winwidth=79
set textwidth=120
set timeoutlen=500
set title " Show a window title
set updatecount=10
" }}}
" {{{ Folding settings
set foldenable
set foldmethod=syntax " Use syntax fold
set foldlevel=99 " Folds are open by default
set foldlevelstart=99 " Folds are open by default (new way)
let ruby_fold=0
let go_fold=0
let lua_fold=1
let javascript_fold=1
" }}}
" {{{ completion options
" set omnifunc=syntaxcomplete#Complete
set complete=.,w,b,u,t " Better Completion
" set completeopt=menuone,noselect
set completeopt=menuone
set completeopt+=noinsert
set completeopt-=preview
set iskeyword+=- " Allow autocomplete to treat thes as part of a completion
set updatetime=300
" }}}
" {{{ Search settings
set magic
set hlsearch " highlight matches
set incsearch " incremental searching
if has('nvim')
set inccommand=nosplit " incremental everything
endif
set ignorecase " searches are case insensitive...
set smartcase " ... unless they contain at least one capital letter
" }}}
" {{{ Whitespace settings
set diffopt=internal,algorithm:patience,indent-heuristic
set nowrap " don't wrap lines
set tabstop=2 " a tab is two spaces
set shiftround " Round intentations to the nearest shiftwidth
set showtabline=2 " When tab labels will be shown
set softtabstop=2 " Number of spaces for a tab
set shiftwidth=2 " an autoindent (with <<) is two spaces
set autoindent " Copy indent from the current line to a new line
set smartindent " Be smart when indenting
set smarttab " Insert "tabstop" spaces when tab is pressed
set expandtab " use spaces, not tabs
set backspace=indent,eol,start " backspace through everything in insert mode
set list " Show invisible characters using listchars
set listchars="" " Reset the listchars
set listchars=tab:›\ " show tabs as lsaquos
set listchars+=trail:· " show trailing spaces as dots
set listchars+=nbsp:· " show trailing non-breaking-spaces as dots
set listchars+=extends:❯ " The character in the last column when the line continues right
set listchars+=precedes:❮ " The character in the first column when the line continues left
" }}}
" {{{ Wildmenu settings
set wildmenu wildmode=longest:full
set wildignorecase
" Ignore these files when auto-completing with tab (for example when opening with :e)
set wildignore+=*.o,*.out,*.obj,.git,*.rbc,*.rbo,*.class,.svn,*.gem " general programming
set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz " compressed files
set wildignore+=*/vendor/gems/*,*/vendor/cache/*,*/.bundle/*,*/.sass-cache/* " vendor and sass
set wildignore+=*/node_modules/* " Node modules
set wildignore+=*/dist/*,*/assets/* " Compiled js code and assets
set wildignore+=tf.plan,*.terraform* " Terraform
set wildignore+=*.swp,*~,._* " Swap and tmp files
set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg,*.svg " binary images
set wildignore+=*.luac " Lua byte code
set wildignore+=*.min.* " Minified web artifacts
set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
set wildignore+=*.orig " Merge resolution files
set wildignore+=*.swp,*.bak,*.pyc " Set wildignore to hid swp, bak and pyc files
set wildignore+=.hg,.git,.svn " Version control
" }}}
" {{{ Matching closing character settings
set showmatch " Display matching parent
set matchtime=4 " Time to display matching parent, in tens of second
set mmp=5000 " Set pattern max memory
" }}}
syntax case match
syntax sync minlines=1024
if !exists("g:syntax_on")
syntax enable
endif
" Autocommands that cant live in after/filetypes
if has('autocmd')
filetype plugin indent on " allow for individual indentations per file type
augroup LargeFile
let g:large_file = 1048576 " 1MB
" Set options:
" eventignore+=FileType (no syntax highlighting etc assumes FileType always on)
" noswapfile (save copy of file)
" bufhidden=unload (save memory when other file is viewed)
" undolevels=-1 (no undo possible)
" \ set eventignore+=FileType |
au BufReadPre *
\ let f=expand("<afile>") |
\ if getfsize(f) > g:large_file |
\ set eventignore=all |
\ setlocal wrap noswapfile bufhidden=unload nohidden syntax=off ft= |
\ else |
\ set eventignore-=FileType |
\ endif
augroup END
augroup Shell
autocmd!
" Make shell scripts executable
au BufWritePost * call MakeScriptExecuteable()
" Make default filetype sh
autocmd BufEnter * if &filetype == "" | setlocal ft=sh | endif
" Fold shell scripts
autocmd FileType sh let g:sh_fold_enabled=3
autocmd FileType sh let g:is_bash=1
augroup end
augroup Numbering
autocmd!
" After opening, jump to last known cursor position unless it's invalid or in an event handler
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
if exists('+relativenumber')
" Show absolute numbers when in insert mode
autocmd InsertEnter * :setlocal norelativenumber
autocmd InsertLeave * :setlocal relativenumber
" Only use relative numbers when the window is active
autocmd BufEnter * :setlocal relativenumber
autocmd WinEnter * :setlocal relativenumber
autocmd BufLeave * :setlocal norelativenumber
autocmd WinLeave * :setlocal norelativenumber
endif
" Only show cursorline in the current window and in normal mode.
autocmd WinLeave,InsertEnter * set nocursorline
autocmd WinEnter,InsertLeave * set cursorline
augroup end
augroup Sizing
autocmd!
" Resize splits when the window is resized
autocmd VimResized * :wincmd =
augroup end
augroup Filetypes
autocmd!
" Filetypes
autocmd BufNewFile,BufRead */.kube/config setlocal ft=yaml
autocmd BufNewFile,BufRead .alias* setlocal ft=sh
autocmd BufNewFile,BufRead *.config setlocal ft=yaml et ts=2 sw=2 sts=2
autocmd BufNewFile,BufRead *.j2 setlocal ft=yaml et ts=2 sw=2 sts=2
autocmd BufNewFile,BufRead *.js setlocal et ts=2 sw=2 sts=2
autocmd BufNewFile,BufRead *.json setlocal et ts=2 sw=2 sts=2 conceallevel=0
autocmd BufNewFile,BufRead *.lua setlocal noet ts=4 sw=4 sts=4
autocmd BufNewFile,BufRead init.lua setlocal et ts=2 sw=2 sts=2
autocmd BufNewFile,BufRead *.py setlocal et ts=4 sw=4 sts=4
autocmd BufNewFile,BufRead *.sh setlocal et ts=2 sw=2 sts=2
autocmd BufNewFile,BufRead */aws/jenkins/* setlocal ft=groovy
autocmd BufNewFile,BufRead */playbooks/vars/*.yml setlocal filetype=yaml.ansible et ts=2 sw=2 sts=2
autocmd BufNewFile,BufRead */tasks/*.yml setlocal filetype=yaml.ansible et ts=2 sw=2 sts=2
autocmd BufNewFile,BufRead Jenkinsfile* setlocal ft=groovy
autocmd BufNewFile,BufRead *.jenkinsfile setlocal ft=groovy
autocmd BufNewFile,Bufread *.spect setlocal ft=spec
autocmd BufNewFile,Bufread *.wsgi setlocal ft=python
autocmd BufNewFile,BufRead *.go setlocal noet ts=4 sw=4 sts=4
autocmd FileType crontab setlocal wrap textwidth=0
autocmd FileType make setlocal noet ts=4 sw=4 sts=4 foldmethod=marker foldlevel=1
autocmd FileType make nnoremap <silent> <leader>d :sp<CR> <c-]>
autocmd FileType markdown setlocal wrap spell spelllang=en_us textwidth=160
autocmd FileType vimwiki setlocal wrap spell spelllang=en_us textwidth=160
autocmd FileType gitconfig setlocal noet ts=8 sw=8 sts=0
autocmd FileType terraform nnoremap <leader>f :Neoformat<CR>
autocmd FileType hcl nnoremap <leader>f :Neoformat<CR>
augroup end
augroup Python
autocmd!
" Python
" Jedi defaults <leader>d to goto
autocmd FileType python nnoremap <leader>sd :sp<CR>:call jedi#goto()<CR>
autocmd FileType python nnoremap <leader>f :Neoformat<CR>
augroup end
augroup Golang
autocmd!
" Golang
autocmd FileType go nnoremap <silent> <leader>d :<C-u>call go#def#Jump('', 0)<CR>
autocmd FileType go nnoremap <silent> <leader>sd :sp<CR> :silent call go#def#Jump('', 0)<CR>
autocmd FileType go nnoremap <silent> <leader>gb :wa<CR> :GoBuild<CR>
autocmd FileType go nnoremap <silent> <leader>gi :wa<CR> :GoImports<CR>
autocmd FileType go nnoremap <silent> <leader>i <Plug>(go-info)
autocmd FileType go nnoremap <silent> <leader>r <Plug>(go-rename)
autocmd FileType go nnoremap <silent> <leader>tf :wa<CR> :GolangTestFocused<CR>
autocmd FileType go nnoremap <silent> <leader>tp :wa<CR> :GolangTestCurrentPackage<CR>
autocmd FileType go nnoremap <silent> <leader>rt <Plug>(go-run-tab)
autocmd FileType go nnoremap <silent> <leader>rs <Plug>(go-run-split)
autocmd FileType go nnoremap <silent> <leader>rv <Plug>(go-run-vertical)
autocmd BufWritePost *.go silent! GoBuild -i
augroup end
augroup Frontend
autocmd!
autocmd FileType javascript nnoremap <leader>f :Prettier<CR>
autocmd FileType html nnoremap <leader>f :call HtmlBeautify()<CR>
autocmd FileType css nnoremap <leader>f :call CSSBeautify()<CR>
" React-goto-definition
autocmd FileType javascript nmap <leader>rd :call ReactGotoDef()<CR>
augroup end
augroup ConfigFiles
autocmd!
autocmd FileType json nnoremap <leader>f :Prettier<CR>
autocmd FileType yaml nnoremap <leader>f :Neoformat<CR>
augroup end
augroup Completion
autocmd!
" (Optional)Hide Info(Preview) window after completions
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
augroup end
augroup Misc
autocmd!
" VimWIKI
autocmd FileType vimwiki nnoremap <silent><leader>M :VimwikiAll2HTML<CR>
" Mardown Preview
autocmd FileType markdown nnoremap <leader>p :MarkdownPreview<CR>
" Neomake
autocmd ColorScheme *
\ hi link NeomakeError SpellBad |
\ hi link NeomakeWarning SpellCap
" Neomake options
" normal mode (after 1s; no delay when writing).
call neomake#configure#automake('nrwi', 1000)
augroup end
endif
" Make directories automatically if they don't already exist.
if !isdirectory(expand(&backupdir))
call mkdir(expand(&backupdir), "p")
endif
if !isdirectory(expand(&directory))
call mkdir(expand(&directory), "p")
endif
if !isdirectory(expand(&undodir))
call mkdir(expand(&undodir), "p")
endif
" Auto-adjust the quickfix window height
au FileType qf call AdjustWindowHeight(3, 10)
function! AdjustWindowHeight(minheight, maxheight)
let l = 1
let n_lines = 0
let w_width = winwidth(0)
while l <= line('$')
" number to float for division
let l_len = strlen(getline(l)) + 0.0
let line_width = l_len/w_width
let n_lines += float2nr(ceil(line_width))
let l += 1
endw
exe max([min([n_lines, a:maxheight]), a:minheight]) . "wincmd _"
endfunction
" Center on c-o
nnoremap <c-o> <c-o>zz
" Don't jump on *
nnoremap * *``
" STATUS LINE
" set statusline=%<%f\ (%{&ft})\ %-4(%m%)%=%-19(%3l,%02c%03V%)
"------------------------------------------------
" Status Line START
set statusline=%<%f\ %h%m%r
set statusline+=%=%-10.60{LspStatus()}\ %-.(%l,%c%V%)\ %P
function! LspStatus() abort
if luaeval('#vim.lsp.buf_get_clients() > 0')
return luaeval("require('lsp-status').status()")
endif
return ''
endfunction
" Status Line END
"------------------------------------------------
" MISC FUNCTIONS
" Edit WorkLog Journal
nnoremap <silent> <leader>wl :e ~/vimwiki/WorkLog.md<CR>
" MISC KEY MAPS
nnoremap <silent> <F2> :set nonumber!<CR>:set relativenumber!<CR>:set foldcolumn=0<CR>
nnoremap <F5> <ESC>:w<CR>:call CallInterpreter()<CR>
" Indent by spaces TODO: <silent>
noremap <silent> {{ :s/^ //e<CR>:nohlsearch<CR>
noremap <silent> }} :s/^/ /e<CR>:nohlsearch<CR>
"noremap <silent> <leader>cc :<C-B>silent <C-E>s/^/<C-R>=escape(b:comment_leader,'\/')<CR>/<CR>:nohlsearch<CR>
"noremap <silent> <leader>cu :<C-B>silent <C-E>s/^\V<C-R>=escape(b:comment_leader,'\/')<CR>//e<CR>:nohlsearch<CR>
"omnicomplete
" inoremap <C-Space> <C-X><C-I>
" Resize splits
nnoremap <silent> + :exe "vertical resize " . (winwidth(0) * 4/3)<CR>
nnoremap <silent> - :exe "vertical resize " . (winwidth(0) * 3/4)<CR>
" " Copy to clipboard
vnoremap <leader>y "+y
nnoremap <leader>Y "+yg_
nnoremap <leader>y "+y
nnoremap <leader>yy "+yy
" " Paste from clipboard
nnoremap <leader>p "+p
nnoremap <leader>P "+P
vnoremap <leader>p "+p
vnoremap <leader>P "+P
" Move around splits with <c-hjkl>
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-h> <c-w>h
nnoremap <c-l> <c-w>l
" switch tabs with Ctrl left and right
nnoremap <C-right> :tabnext<CR>
nnoremap <C-left> :tabprevious<CR>
" switch buffers with Ctrl up and down
nnoremap <C-up> :bn<CR>
nnoremap <C-down> :bN<CR>
" and whilst in insert mode
inoremap <C-right> <Esc>:tabnext<CR>
inoremap <C-left> <Esc>:tabprevious<CR>
" switch buffers with Ctrl up and down in insert mode
inoremap <C-up> <Esc>:bn<CR>
inoremap <C-down> <Esc>:bN<CR>
" New tab shortcut
nnoremap <leader>w :tabnew<CR>:TW<CR>
" Swap files
nnoremap <leader><leader> <c-^>
nnoremap <C-C> :call DWM_Close()<CR>
nnoremap <C-A> :call DWM_Focus()<CR>
"clear highlight search
nmap <silent> <leader><space> :nohlsearch<CR>
nnoremap <silent> <leader>s :StripWhiteSpaces<CR>
"Fix shell expansion with putty
map [[ ?{<CR>w99[{
map ][ /}<CR>b99]}
map ]] j0[[%/{<CR>
map [] k$][%?}<CR>
"tab handling
nnoremap <leader>t :tab sp<CR>
nnoremap <leader>c :tabc<CR>
"make Y behave more like C and D
nmap Y y$
if !empty(glob($HOME . '/anaconda3/bin/python3'))
let g:python3_host_prog = $HOME . '/anaconda3/bin/python3'
endif
if has('python3') " if dynamic py|py3, this line already activates python3.
let s:python_version = 3
elseif has('python')
let s:python_version = 2
else
let s:python_version = 0
endif
function! ChompedSystem( ... )
return substitute(call('system', a:000), '\n', '', 'g')
endfunction
" Python site-packages
let g:site_packages = ChompedSystem('python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"')
" FZF configuration
nnoremap <C-p> :execute ':Files' . g:site_packages<CR>
nnoremap <C-T> :Tags<CR>
nnoremap <C-\> :split<CR> :FZF<CR>
nnoremap <C-t> :FZF<CR>
" Rg configuration
nnoremap <leader>a :execute 'Rg '.input('Rg: ')<CR>
nnoremap <leader>A :Rg <C-r><C-w><CR>
" nnoremap <leader>l :execute 'Locate "'.input('Locate: ').'"'<CR>
" Change to directory of current file
nnoremap <leader>cd :lcd%:p:h<CR>
" fix syntax hl:
nnoremap U :syntax sync fromstart<CR>:redraw!<CR>
nnoremap U :syntax sync fromstart<CR>:redraw!<CR>
" Toggle undo tree
nnoremap <leader>u :UndotreeToggle<CR>
" ------------------------------------------"
" Plugin Settings
" ----------------------------------------- "
" tagbar
nnoremap <silent> <leader>b :TagbarToggle<CR>
" autocmd FileType * nested :call tagbar#autoopen(0)
let g:tagbar_compact = 1
let g:tagbar_type_ansible = {
\ 'ctagstype' : 'ansible',
\ 'kinds' : [
\ 't:Tasks',
\ 'h:Hosts'
\ ],
\ 'sort' : 0
\ }
let g:tagbar_type_terraform = {
\ 'ctagstype' : 'terraform',
\ 'kinds' : [
\ 'd:Data',
\ 'r:Resources',
\ 'm:Modules',
\ 'o:Outputs',
\ 'P:Providers',
\ 'v:Variables',
\ 'f:TFVars'
\ ],
\ 'sort': 0
\ }
if executable('cmake-language-server')
au User lsp_setup call lsp#register_server({
\ 'name': 'cmake',
\ 'cmd': {server_info->['cmake-language-server']},
\ 'root_uri': {server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), 'build/'))},
\ 'whitelist': ['cmake'],
\ 'initialization_options': {
\ 'buildDirectory': 'build',
\ }
\})
endif
" gutentags
set statusline+=%{gutentags#statusline()}
let g:gutentags_define_advanced_commands = 1 " Extra Debugging
let g:gutentags_file_list_command = {
\ 'markers': {
\ '.pythontags': $HOME . '/bin/python-file-lister'
\ }
\}
let g:gutentags_add_default_project_roots = 0
let g:gutentags_project_root = ['.git', '.pythontags', '.forcetags', '.envrc']
let g:gutentags_generate_on_new = 1
let g:gutentags_generate_on_missing = 1
let g:gutentags_generate_on_write = 1
let g:gutentags_generate_on_empty_buffer = 0
" gutentags-ctags
let g:gutentags_ctags_exclude_wildignore = 1
let g:gutentags_ctags_tagfile = '.tags'
let g:gutentags_ctags_extra_args = [
\ '--tag-relative=yes',
\ '--fields=+ailmnS',
\ ]
" ansible-vim
let g:ansible_unindent_after_newline = 1
let g:ansible_extra_keywords_highlight = 1
" Go settings
let g:go_gocode_propose_source = 1
let g:go_auto_type_info = 1
let g:go_dispatch_enabled = 1
let g:go_fmt_fail_silently = 0
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_operators = 1
let g:go_jump_to_error = 1
let g:go_play_open_browser = 0
let g:go_def_mapping_enabled = 0
let g:go_def_reuse_buffer = 1
let g:go_echo_commands_disabled = ['godef']
let g:go_echo_command_info = 0
" vim-illuminate
" Time in milliseconds (default 250)
let g:Illuminate_delay = 250
" Don't highlight word under cursor (default: 1)
let g:Illuminate_highlightUnderCursor = 1
" Don't illumilate on these filetypes
let g:Illuminate_ftblacklist = ['nerdtree']
" Visual highlight
hi link illuminatedWord Visual
" Rainbow
let g:rainbow_active = 1
" Neoformat
" Python formatters
let g:neoformat_python_autoflake = {
\ 'exe': 'autoflake',
\ 'stdin': 0,
\ 'replace': 1,
\ 'args': [
\ '--in-place',
\ '--remove-all-unused-imports',
\ '--ignore-init-module-imports',
\ '--expand-star-imports',
\ '--remove-unused-variables',
\ '--remove-duplicate-keys',
\ ],
\ }
let g:neoformat_enabled_python = ['isort', 'black']
" YAML formatters
let g:neoformat_enabled_yaml = ['beautifyk8s']
let g:neoformat_yaml_beautifyk8s = {
\ 'exe': 'beautify-k8s',
\ 'args': ['-i'],
\ 'stdin': 0,
\ 'replace': 0,
\ 'valid_exit_codes': [0],
\ }
" Enable tab to spaces conversion
let g:neoformat_basic_format_retab = 1
" Enable trimmming of trailing whitespace
let g:neoformat_basic_format_trim = 1
" Run all enabled formatters (by default Neoformat stops after the first formatter succeeds)
let g:neoformat_run_all_formatters = 1
" Have Neoformat only msg when there is an error
let g:neoformat_only_msg_on_error = 1
" {{{ Neomake options
:highlight NeomakeSign guifg=Yellow guibg=#dc322f gui=bold
let g:neomake_makeprg_buffer_output = 0
"let g:neomake_open_list = 1
let g:neomake_python_enabled_makers = ['python', 'frosted', 'flake8']
let g:neomake_javascript_enabled_makers = ['eslint']
let g:neomake_dockerfile_enabled_makers = []
let g:neomake_java_enabled_makers = []
let g:neomake_error_sign = {
\ 'text': '•',
\ 'texthl': 'NeomakeSign',
\ }
let g:neomake_warning_sign = {
\ 'text': '!',
\ 'texthl': 'NeomakeSign',
\ }
let g:neomake_tempfile_dir = '/tmp/neomake%:p:h'
" }}}
" Firefox refresh
"let g:firefox_refresh_files = "*.js"
"let $firefox_refresh_host = "webclient"
" Airline
let g:airline#extensions#tabline#enabled = 1
let g:airline_detect_modified=1
let g:airline_detect_paste=1
let g:airline_mode_map = {} " see source for the defaults
" autopep8
let g:autopep8_max_line_length=120
let g:autopep8_pep8_passes=100
let g:autopep8_aggressive=2
let g:autopep8_indent_size=4
let g:autopep8_disable_show_diff=1
let g:autopep8_on_save = 1
" vim-dirdiff
let g:DirDiffAddArgs = "-w" " ignore white space in diff
let g:DirDiffEnableMappings = 1
let g:DirDiffExcludes = "*.*ar,*.bak,*.crt,*.csr,*.enc*,*.lock*,*.gz,*.key,*.manifest,*.pem,*.pid,*.pub,*.rpm,.Makefile.*,.ssh,.asdf,.git*,.tags*,.terraform,artifact*,bin,images,kubeconfig,mirror,packer-*,retag-*,rpm-*,s3-*,tmp"
let g:DirDiffIgnore = ""
let g:DirDiffSort = 1
" terraform
let g:terraform_align = 1
let g:terraform_commentstring = '//%s'
let g:terraform_fmt_on_save = 1
let g:terraform_completion_keys = 0
let g:terraform_registry_module_completion = 1
" For conceal markers.
if has('conceal')
set conceallevel=0 concealcursor=niv
endif
" Thyme pormordio timer
nmap <silent><leader>p :silent !thyme -d<CR>
" vim-javascript
let g:javascript_plugin_jsdoc = 1
" Vimwiki
" Turn off URL shortening
let g:vimwiki_url_maxsave=0
let g:vimwiki_folding='expr' "this allows the folding to work for markdown
let g:vimwiki_global_ext = 0
let g:vimwiki_hl_headers = 1
let g:vimwiki_list = [{
\ 'auto_export': 1,
\ 'auto_header' : 1,
\ 'automatic_nested_syntaxes': 1,
\ 'autotags': 1,
\ 'custom_wiki2html': '~/vimwiki/scripts/convert.py',
\ 'ext': '.md',
\ 'links_space_char' : '_',
\ 'list_margin': 0,
\ 'path': '~/vimwiki',
\ 'path_html': '~/vimwiki/html',
\ 'syntax': 'markdown',
\ 'template_default': 'GitHub',
\ 'template_ext': 'html5',
\ 'template_path': '~/vimwiki/templates/',
\ 'nested_syntaxes': {
\ 'bash': 'sh',
\ 'elixir': 'elixir',
\ 'java': 'java',
\ 'javascript': 'javascript',
\ 'js': 'javascript',
\ 'json': 'javascript',
\ 'python': 'python',
\ 'ruby': 'ruby',
\ 'yaml': 'yaml'
\ },
\ }]
" \ 'path_html': '~/vimwiki/html/',
autocmd FileType vimwiki set spell spelllang=en_us complete+=kspell
vnoremap <Leader>ci y:tabnew <bar> setlocal buftype=nofile bufhidden=hide noswapfile <bar> r! echo '<C-R>"' <bar> showcertinfo 2>&1<CR><CR>
function! GoogleSearch()
let searchterm = expand('<cword>')
if &filetype != ""
let searchterm .= "+" . &filetype
endif
silent! exec "silent! !open \"http://google.com/search?q=" . searchterm . "\" &"
endfunction
nmap <Leader>gs :call GoogleSearch()<CR>
" Markdown Preview
let g:mkdp_theme = 'light'
let g:mkdp_open_to_the_world = 1
let g:mkdp_page_title = '${name}'
" options for markdown render
" mkit: markdown-it options for render
" katex: katex options for math
" uml: markdown-it-plantuml options
" maid: mermaid options
" disable_sync_scroll: if disable sync scroll, default 0
" sync_scroll_type: 'middle', 'top' or 'relative', default value is 'middle'
" middle: mean the cursor position alway show at the middle of the preview page
" top: mean the vim top viewport alway show at the top of the preview page
" relative: mean the cursor position alway show at the relative positon of the preview page
" hide_yaml_meta: if hide yaml metadata, default is 1
" sequence_diagrams: js-sequence-diagrams options
" content_editable: if enable content editable for preview page, default: v:false
" disable_filename: if disable filename header for preview page, default: 0
let g:mkdp_preview_options = {
\ 'mkit': {},
\ 'katex': {},
\ 'uml': {},
\ 'maid': {},
\ 'disable_sync_scroll': 0,
\ 'sync_scroll_type': 'middle',
\ 'hide_yaml_meta': 1,
\ 'sequence_diagrams': {},
\ 'flowchart_diagrams': {},
\ 'content_editable': v:false,
\ 'disable_filename': 1,
\ 'toc': {}
\ }
let g:copilot_filetypes = {
\ 'yaml': v:true,
\ 'markdown': v:true,
\ 'gitcommit': v:true,
\ 'gitrebase': v:true,
\ '.': v:true,
\ }
let g:copilot_no_tab_map = v:true
imap <silent><script><expr> <C-J> copilot#Accept("\<CR>")
inoremap <C-h> <Plug>(copilot-suggest)
nnoremap <C-x> :Copilot panel<CR>
inoremap <C-x> <C-o>:Copilot panel<CR>