-
Notifications
You must be signed in to change notification settings - Fork 2
/
.vimrc
1547 lines (1343 loc) · 45.4 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
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"
" Ryan Kanno <[email protected]>
" @ryankanno
"
" vim-plug (d/l + install)
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
let g:user="Ryan Kanno"
let g:email="[email protected]"
let s:uname = substitute(system("uname -s"), '\n', '', '')
" Plugins {{{
call plug#begin()
if !exists('g:vscode')
Plug 'ctrlpvim/ctrlp.vim'
Plug 'rhysd/devdocs.vim'
Plug 'editorconfig/editorconfig-vim'
Plug 'mattn/emmet-vim'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'alok/notational-fzf-vim'
Plug 'phanimahesh/goyo.vim'
Plug 'haya14busa/is.vim'
Plug 'cohama/lexima.vim'
Plug 'junegunn/limelight.vim'
Plug 'wfxr/minimap.vim', {'do': ':!cargo install --locked code-minimap'}
Plug 'justinmk/molokai'
Plug 'myusuf3/numbers.vim'
Plug 'ethanmuller/scratch.vim'
Plug 'majutsushi/tagbar'
Plug 'wellle/targets.vim'
Plug 'vim-scripts/TaskList.vim'
Plug 'tpope/vim-abolish'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'Chiel92/vim-autoformat'
Plug 'ryanoasis/vim-devicons'
Plug 'dodie/vim-disapprove-deep-indentation'
Plug 'arecarn/vim-fold-cycle'
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
Plug 'ludovicchabant/vim-gutentags'
Plug 'andymass/vim-matchup'
Plug 'simnalamburt/vim-mundo'
Plug 'junegunn/vim-plug'
Plug 'tpope/vim-projectionist'
Plug 'vimjas/vim-python-pep8-indent'
Plug 'tpope/vim-repeat'
Plug 'machakann/vim-sandwich'
Plug 'tpope/vim-speeddating'
Plug 'mhinz/vim-startify'
Plug 'dstein64/vim-startuptime'
Plug 'aperezdc/vim-template'
Plug 'vim-test/vim-test'
Plug 'tadaa/vimade'
if has('nvim')
Plug 'gbprod/cutlass.nvim'
Plug 'shellRaining/hlchunk.nvim'
Plug 'gbprod/yanky.nvim'
Plug 'ray-x/lsp_signature.nvim'
Plug 'williamboman/mason.nvim'
Plug 'williamboman/mason-lspconfig.nvim'
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/cmp-emoji'
Plug 'hrsh7th/cmp-path'
Plug 'lukas-reineke/cmp-rg'
Plug 'ray-x/cmp-treesitter'
Plug 'hrsh7th/nvim-cmp'
Plug 'L3MON4D3/LuaSnip', {'tag': 'v2.*', 'do': 'make install_jsregexp'}
Plug 'saadparwaiz1/cmp_luasnip'
Plug 'mireq/luasnip-snippets'
Plug 'onsails/lspkind.nvim'
Plug 'folke/trouble.nvim'
Plug 'mfussenegger/nvim-dap'
Plug 'nvim-neotest/nvim-nio'
Plug 'rcarriga/nvim-dap-ui'
Plug 'utilyre/barbecue.nvim'
Plug 'smoka7/hop.nvim'
Plug 'nvim-tree/nvim-tree.lua'
Plug 'akinsho/toggleterm.nvim', {'tag' : 'v2.10.0'}
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'zbirenbaum/copilot.lua'
Plug 'zbirenbaum/copilot-cmp'
Plug 'echasnovski/mini.nvim'
Plug 'SmiteshP/nvim-navic'
Plug 'gennaro-tedesco/nvim-peekup'
Plug 'xiyaowong/transparent.nvim'
" avante
Plug 'stevearc/dressing.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'MunifTanjim/nui.nvim'
Plug 'HakonHarnes/img-clip.nvim'
Plug 'MeanderingProgrammer/render-markdown.nvim'
Plug 'yetone/avante.nvim'
else
Plug 'github/copilot.vim'
Plug 'moll/vim-bbye'
Plug 'tpope/vim-commentary'
Plug 'itchyny/vim-cursorword'
Plug 'svermeulen/vim-cutlass'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'matze/vim-move'
Plug 'junegunn/vim-peekaboo'
Plug 'sheerun/vim-polyglot'
Plug 'vim-scripts/YankRing.vim'
endif
endif
call plug#end()
" }}}
" Abbreviations {{{
iab me@ Ryan Kanno <[email protected]>
iab date@ <C-R>=strftime("%A, %B %e %Y %I:%M:%S %p %Z")<CR>
" }}}
" General {{{
let mapleader="," " set mapleader
set nocompatible " disable older vi compatibility
set modeline " respect other
set encoding=utf-8 " use utf-8 encoding
set number " set line numbers
set lazyredraw " lazy
set ttyfast
set ruler " show ruler
set rulerformat=%55(%{strftime('%a\ %b\ %e\ %I:%M\ %p')}\ %5l,%-6(%c%V%)\ %P%)
set laststatus=2 " always show last status
set history=10000 " 10000 lines of history
set undolevels=10000 " 10000 levels of undo
set clipboard^=unnamed,unnamedplus " https://stackoverflow.com/questions/30691466/what-is-difference-between-vims-clipboard-unnamed-and-unnamedplus-settings
set ffs=unix,dos,mac " set file format to unix, win, then old mac
set hidden " enable hidden files
set backspace=indent,eol,start " enable backspace over indent, EOL, START
" create undo structures
if has('nvim')
set undodir=$HOME/.nvim_undo
if ! isdirectory(expand(&undodir))
call mkdir(&undodir, 'p', 0700)
endif
else
set undodir=$HOME/.vim_undo
if ! isdirectory(expand(&undodir))
call mkdir(&undodir, 'p', 0700)
endif
endif
set undofile
set backupext=.bak " append .bak to backup files
set backupdir=$HOME/.vim_backups " directory to store backup files
if ! isdirectory(expand(&backupdir))
call mkdir(&backupdir, 'p', 0700)
endif
set directory=$HOME/.vim_swaps " directory to store swap files
if ! isdirectory(expand(&directory))
call mkdir(&directory, 'p', 0700)
endif
set autowrite " enable buffers to be saved on suspend
" }}}
" Theme {{{
if has("syntax")
syntax on
endif
set synmaxcol=256
set termguicolors " sets colors
set background=dark " sets the background color (I like it dark)
" Molokai
colorscheme molokai " <3 colorscheme ftw.
" }}}
" Visual {{{
set cursorline " highlight current line
set nowrap " nowrap
set showcmd " show cmd
set showmatch " show matching brackets
set showbreak=↪ " show '↪' if line is longer than screen
set mat=5 " how many tenths of a second to blink matching brackets
set incsearch " show search matches as you type
set novisualbell " no error bells
set noerrorbells " no error bells
set title " sets the title
set wildmenu " show autocomplete options
set textwidth=79 " sets the text width
set tabpagemax=10 " show 10 tabs
" highlight lines over 80 characters
highlight OverLength ctermbg=darkred ctermfg=white guibg=#AE0000
match OverLength /\%80v.\+/
" show color column
if exists('+colorcolumn')
set colorcolumn=80
endif
" }}}
" Neovim {{{
if has('nvim')
let g:loaded_python_provider=0
endif
" }}}
"
" Search {{{
set ignorecase " case insensitive search
set smartcase
set magic " enable advanced regular expressions
set hlsearch " enables highlighting search
" }}}
" Text {{{
set autoindent " use curr line's indent to set indent of new line
set smartindent " vim guesses indent level
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set gdefault " the /g flag on :s substitutions by default
" }}}
" Wildmenu {{{
if has('wildmenu')
if ! has('nvim')
set wildmode=list:longest
endif
set wildignorecase
set wildignore+=.git,.hg,.svn,.bzr
set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest,*.class,*.out,*.pyc,*.so,*.com,
set wildignore+=*.swp,*.swo,*.swn,*.swm,*.tmp,*/tmp/*,.lock,*.DS_Store,._*
set wildignore+=*.ai,*.bmp,*.gif,*.ico,*.jpg,*.jpeg,*.png,*.psd,*.webp
set wildignore+=*.avi,*.divx,*.mp4,*.webm,*.mov,*.m2ts,*.mkv,*.vob,*.mpg,*.mpeg
set wildignore+=*.mp3,*.mp4,*.oga,*.ogg,*.wav,*.flac
set wildignore+=*.eot,*.otf,*.ttf,*.woff
set wildignore+=*.doc,*.pdf,*.cbr,*.cbz
set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz
set wildignore+=*.jpg,*.png,*.jpeg,*.bmp,*.gif,*.tiff,*.svg,*.ico
set wildignore+=*/node_modules/*
set wildignore+=*.sqlite*
set wildignore+=__pycache__,*.egg-info,.pytest_cache,.mypy_cache,.ruff_cache
set wildignore+=*_rsa,*_rsa.*,*_dsa,*_dsa.*,*_keys,*.pem,*.key,*.gpg
set wildignore+=*/.backup,*/.vim-backup,*/.nvim-backup
set wildignore+=*/.swap,*/.vim-swap,*/.nvim-swap
set wildignore+=*/.undo,*/.vim-undo,*/.nvim-undo
set wildignore+=tags,.tags
endif
" }}}
" Folding {{{
set foldenable " enable folding
set foldmethod=marker
set foldlevel=0
set commentstring=\ #\ %s
nnoremap <Space> za " space toggles folding
vnoremap <Space> za " space toggles folding
function! CustomFoldText(spacer, ...) " {{{
let spacer = a:spacer
if exists("a:1")
let max_num_cols = a:1
else
let max_num_cols = winwidth(0) - &fdc - 4
endif
" Skip empty lines"
let first_line_start = v:foldstart
while getline(first_line_start) =~ '^\s*$' | let first_line_start = nextnonblank(first_line_start + 1)
endwhile
if first_line_start > v:foldend
let line = getline(v:foldstart)
else
let line = substitute(getline(first_line_start), '\t', repeat(' ', &tabstop), 'g')
endif
let num_folded_lines = v:foldend - v:foldstart
let fold_percentage = printf("%.1f", (num_folded_lines * 1.0) / line("$")* 100)
let folded_line_display = num_folded_lines . " lines [" . fold_percentage . "%]"
let spacer_fill = max_num_cols - strwidth(line) - strwidth(folded_line_display)
return line . repeat(spacer, spacer_fill) . folded_line_display
endfunction " }}}
set foldtext=CustomFoldText('.',80)
" }}}
" Filetype {{{
filetype plugin indent on
autocmd BufNewFile,BufRead *.json set filetype=json
autocmd BufNewFile,BufRead *.scss,*.sass set filetype=sass
autocmd BufNewFile,BufRead *.ts set filetype=typescript
autocmd BufNewFile,BufRead *.tsx set filetype=typescriptreact
autocmd BufNewFile,BufRead *.jsx set filetype=javascriptreact
autocmd BufNewFile,BufRead *.vue set filetype=javascript
autocmd BufNewFile,BufRead *.jinja,*.jinja2,*.j2 set filetype=jinja
autocmd FileType css setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
autocmd FileType html,htmldjango,xhtml,haml,jinja setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2 textwidth=0
autocmd FileType javascript,typescript,typescriptreact,javascriptreact setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
autocmd FileType json setlocal fdm=syntax
autocmd FileType make setlocal noexpandtab
autocmd FileType python setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4
autocmd FileType ruby setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
autocmd FileType sass setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
autocmd FileType yaml setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
autocmd Filetype crontab setlocal nobackup nowritebackup
" }}}
" Command Line {{{
" change working directory to that of file
cmap <Leader>cd lcd %:p:h<CR>:pwd<CR>
" bash like commands in command mode
cnoremap <C-a> <Home>
cnoremap <C-e> <End>
cnoremap <C-k> <C-U>
cnoremap <C-p> <Up>
cnoremap <C-n> <Down>
" }}}
" Keyboard Mapping {{{
" remap 0 to first word (going to the first col is kinda useless)
map 0 ^
" fix typos with e/w/q/a
" from: http://blog.sanctum.geek.nz/vim-command-typos/
if has("user_commands")
command! -bang -nargs=* -complete=file E e<bang> <args>
command! -bang -nargs=* -complete=file W w<bang> <args>
command! -bang -nargs=* -complete=file Wq wq<bang> <args>
command! -bang -nargs=* -complete=file WQ wq<bang> <args>
command! -bang Wa wa<bang>
command! -bang WA wa<bang>
command! -bang Q q<bang>
command! -bang QA qa<bang>
command! -bang Qa qa<bang>
endif
" fix teh broken
nnoremap / /\v
vnoremap / /\v
" remap ESC in insert mode to jk - faster than jj?
inoremap jk <ESC>
inoremap kj <ESC>
" simplify window navigation with ctrl
nnoremap <C-j> <C-W>j
nnoremap <C-k> <C-W>k
nnoremap <C-h> <C-W>h
nnoremap <C-l> <C-W>l
" make Y act like C/D
nmap Y y$
" ; for : in normal/visual
nnoremap ; :
vnoremap ; :
" clear search matching across all buffers
noremap <Leader><space> :noh<CR>:call clearmatches()<CR>
" match braces using a tab
map <TAB> %
" <Leader><Leader> to HopWord
map <Leader><Leader> :HopWord<CR>
" <Leader>_ to HopLineStart
map <Leader>_ :HopLineStart<CR>
" <Leader>B to open :Buffers
map <Leader>B :<C-u>Buffers<CR>
" <Leader>cc to comment
if has('nvim')
lua << EOF
require('mini.comment').setup({
mappings = {
comment = '<Leader>c',
comment_line = '<Leader>cc',
comment_visual = '<Leader>c',
text_object = '<Leader>c',
}
})
EOF
else
nmap <Leader>cc <Plug>CommentaryLine
endif
" <Leader>cd switches to directory of open buffer
nnoremap <Leader>cd :cd %:p:h<CR>:pwd<CR>
" <Leader>cf copies relative path to clipboard
nnoremap <Leader>cf :let @+=expand("%")<CR>
" <Leader>cF copies absolute path to clipboard
nnoremap <Leader>cF :let @+=expand("%:p")<CR>
" <Leader>dbb to toggle breakpoint
nnoremap <Leader>dbb :DapToggleBreakpoint<CR>
" <Leader>dbc to continue debugging
nnoremap <Leader>dbc :DapContinue<CR>
" <Leader>dbo to open DapUI
nnoremap <Leader>dbo :lua require("dapui").open()<CR>
" <Leader>f to start an `rg` search using FZF
map <Leader>f :Rg<space>
" <Leader>F to start a `Files` search using FZF
map <Leader>F :<C-u>Files<CR>
" <Leader>h/l to go to previous/next in jumplist
nnoremap <Leader>h <C-O>
nnoremap <Leader>l <C-i>
" <Leader>hn to HopNodes
map <Leader>hn :HopNodes<CR>
" Remap K to call devdocs in specific filetypes
let g:devdocs_filetype_map = {
\ 'ruby': 'rails',
\ 'typescriptreact': 'react',
\ 'javascriptreact': 'react',
\ 'javascript.test': 'jest',
\ }
let g:devdocs_open_cmd = 'firefox'
augroup plugin-devdocs
autocmd!
autocmd FileType bash,c,cpp,go,rust,python nmap <buffer><leader>DD <Plug>(devdocs-under-cursor)
augroup END
" <Leader>nt to toggle NvimTreeToggle
map <Leader>nt :NvimTreeToggle<CR>
" <Leader>nf to reveal file in active buffer in NvimTree
map <Leader>nf :NvimTreeFindFile<CR>
" <Leader>num to toggle relative numbers
map <Leader>num :NumbersToggle<CR>
let g:numbers_exclude = ['goyo_pad', 'minibufexpl', 'nvim-tree', 'tagbar']
" ctrl-p shortcuts
let g:ctrlp_map = '<Leader>p'
let g:ctrlp_cmd = 'CtrlPMixed'
if executable('rg')
set grepprg=rg\ --color=never
let g:ctrlp_user_command = 'rg %s --files --hidden --color=never --glob ""'
let g:ctrlp_use_caching = 0
endif
" <Leader>s to open scratch in horizontal split window
map <Leader>s :Sscratch<CR>
" <Leader>S to open scratch in vertical split window
map <Leader>S :Vscratch<CR>
" CTags
set tags+=./tags;/
map <Leader>tag :!uctags --extra=+f -R *<CR><CR>
map <C-\> :tab split<CR>:exec("tag ".expand("<cword>"))<CR>
map <D-]> :vsplit <CR>:exec("tag ".expand("<cword>"))<CR>
" <Leader>tb to open Tagbar
map <Leader>tb :TagbarToggle<CR>
let g:tagbar_type_javascript = {
\ 'ctagstype': 'javascript',
\ 'kinds': [
\ 'A:arrays',
\ 'P:properties',
\ 'T:tags',
\ 'O:objects',
\ 'G:generator functions',
\ 'F:functions',
\ 'C:constructors/classes',
\ 'M:methods',
\ 'V:variables',
\ 'I:imports',
\ 'E:exports',
\ 'S:styled components'
\ ]}
" <Leader>u to toggle Mundo
nnoremap <Leader>u :MundoToggle<CR>
let g:mundo_prefer_python3 = 1
let g:mundo_right = 1
" <Leader>W to open :Windows
map <Leader>W :<C-u>Windows<CR>
" <Leader>ws to clean trailing white space
map <Leader>ws :%s/\s\+$//e<CR>
" <Leader>x to show TODO list
map <Leader>x <Plug>TaskList
" <Leader>y to bring up yanky.nvim
map <Leader>Y :YankyRingHistory<CR>
" <F2> to toggle invisible characters
map <silent> <F2> :set invlist<CR>
" <F3> to toggle Autoformat
noremap <F3> :Autoformat<CR>
" }}}
" Plugins {{{
" vim-cutlass
nnoremap x d
xnoremap x d
nnoremap xx dd
nnoremap X D
if has('nvim')
lua << EOF
require("cutlass").setup({
cut_key = 'x',
})
EOF
endif
" hlchunk.nvim
if has('nvim')
lua << EOF
require('hlchunk').setup({
indent = {
enable = true,
use_treesitter = true
},
chunk = {
enable = true,
use_treesitter = true
},
blank = {
enable = false,
use_treesitter = true
},
line_num = {
enable = true,
use_treesitter = true
}
})
EOF
endif
" yanky.nvim
if has('nvim')
lua << EOF
require("yanky").setup({})
vim.keymap.set({"n","x"}, "p", "<Plug>(YankyPutAfter)")
vim.keymap.set({"n","x"}, "P", "<Plug>(YankyPutBefore)")
vim.keymap.set({"n","x"}, "gp", "<Plug>(YankyGPutAfter)")
vim.keymap.set({"n","x"}, "gP", "<Plug>(YankyGPutBefore)")
vim.keymap.set("n", "<c-p>", "<Plug>(YankyPreviousEntry)")
vim.keymap.set("n", "<c-n>", "<Plug>(YankyNextEntry)")
-- vim-unimpaired
vim.keymap.set("n", "]p", "<Plug>(YankyPutIndentAfterLinewise)")
vim.keymap.set("n", "[p", "<Plug>(YankyPutIndentBeforeLinewise)")
vim.keymap.set("n", "]P", "<Plug>(YankyPutIndentAfterLinewise)")
vim.keymap.set("n", "[P", "<Plug>(YankyPutIndentBeforeLinewise)")
vim.keymap.set("n", ">p", "<Plug>(YankyPutIndentAfterShiftRight)")
vim.keymap.set("n", "<p", "<Plug>(YankyPutIndentAfterShiftLeft)")
vim.keymap.set("n", ">P", "<Plug>(YankyPutIndentBeforeShiftRight)")
vim.keymap.set("n", "<P", "<Plug>(YankyPutIndentBeforeShiftLeft)")
vim.keymap.set("n", "=p", "<Plug>(YankyPutAfterFilter)")
vim.keymap.set("n", "=P", "<Plug>(YankyPutBeforeFilter)")
EOF
endif
" nvim-lsp
if has('nvim')
lua << EOF
require("mason").setup({
automatic_installation = true,
ui = {
icons = {
package_installed = "✓",
package_pending = "➜",
package_uninstalled = "✗"
}
}
})
require("mason-lspconfig").setup({
ensure_installed = {
"bashls",
"clangd",
"cssls",
"dagger",
"dockerls",
"docker_compose_language_service",
"elp",
"gopls",
"html",
"htmx",
"jinja_lsp",
"jsonls",
"lua_ls",
"marksman",
"nil_ls",
"pyright",
"ruff",
"rust_analyzer",
"tailwindcss",
"taplo",
"ts_ls",
"zls"
}
})
local lsp_capabilities = require('cmp_nvim_lsp').default_capabilities()
require'mason-lspconfig'.setup_handlers{
function (server_name) -- default handler (optional)
require'lspconfig'[server_name].setup{capabilities = lsp_capabilities}
end,
-- https://github.com/astral-sh/ruff-lsp/issues/384
['pyright'] = function()
require'lspconfig'.pyright.setup{
settings = {
pyright = {
disableOrganizeImports = true,
disableTaggedHints = true,
},
python = {
analysis = {
diagnosticMode = "off",
diagnosticSeverityOverrides = {
-- https://github.com/microsoft/pyright/blob/main/docs/configuration.md#type-check-diagnostics-settings
reportUndefinedVariable = "none",
},
}
}
}
}
end,
}
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, { desc = 'diagnostic.open_float' })
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'diagnostic.goto_prev' })
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'diagnostic.goto_next' })
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, { desc = 'diagnostic.setloclist' })
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
local function buf_set_keymap(key, func, desc, ...)
local rest = { ... }
local need_xmap = rest[1]
local mode = need_xmap and { 'n', 'x' } or 'n'
local opts = { buffer = ev.buf, desc = 'lsp.' .. desc }
vim.keymap.set(mode, key, func, opts)
end
buf_set_keymap('gD', vim.lsp.buf.declaration, 'declaration')
buf_set_keymap('gd', vim.lsp.buf.definition, 'definition')
buf_set_keymap('gi', vim.lsp.buf.implementation, 'implementation')
buf_set_keymap('<C-k>', vim.lsp.buf.signature_help, 'signature_help')
buf_set_keymap('K', vim.lsp.buf.hover, 'hover')
buf_set_keymap('<SPACE>wa', vim.lsp.buf.add_workspace_folder, 'add_workspace_folder')
buf_set_keymap('<SPACE>wr', vim.lsp.buf.remove_workspace_folder, 'remove_workspace_folder')
buf_set_keymap('<SPACE>wl', function() vim.print(vim.lsp.buf.list_workspace_folders()) end, 'list_workspace_folders')
buf_set_keymap('<SPACE>D', vim.lsp.buf.type_definition, 'type_definition')
buf_set_keymap('<SPACE>rn', vim.lsp.buf.rename, 'rename')
buf_set_keymap('<SPACE>ca', vim.lsp.buf.code_action, 'code_action', true)
buf_set_keymap('gr', vim.lsp.buf.references, 'references')
buf_set_keymap('<SPACE>f', function() vim.lsp.buf.format { async = true } end, 'format', true)
if vim.lsp.get_clients == nil then
vim.lsp.get_clients = vim.lsp.get_active_clients
end
for _, client in pairs(vim.lsp.get_clients()) do
if client.name == "tailwindcss" then
client.server_capabilities.completionProvider.triggerCharacters = { '"', "'", "`", ".", "(", "[", "!", "/", ":" }
end
end
end,
})
EOF
endif
" luasnip / cmp
if has('nvim')
lua << EOF
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
require('luasnip_snippets.common.snip_utils').setup()
local luasnip = require 'luasnip'
luasnip.setup({
load_ft_func = require('luasnip_snippets.common.snip_utils').load_ft_func,
ft_func = require('luasnip_snippets.common.snip_utils').ft_func,
enable_autosnippets = true,
-- Uncomment to enable visual snippets triggered using <c-x>
-- store_selection_keys = '<c-x>',
})
local lspkind = require('lspkind')
local cmp = require('cmp')
cmp.setup {
formatting = {
format = lspkind.cmp_format({
mode = "symbol_text",
menu = ({
copilot = "[Copilot]",
treesitter = "[Tree]",
buffer = "[Buffer]",
nvim_lsp = "[LSP]",
luasnip = "[LuaSnip]",
path = "[Path]",
emoji = "[Emoji]",
rg = "[RipGrep]",
})
}),
},
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
}),
sources = cmp.config.sources({
{ name = 'copilot', group_index = 2 },
{ name = 'treesitter', group_index = 2 },
{ name = 'nvim_lsp', group_index = 2 },
{ name = 'luasnip', group_index = 2 },
{ name = 'buffer', group_index = 2 },
{ name = 'path', group_index = 2 },
{ name = 'emoji', group_index = 2 },
{ name = 'rg', group_index = 2 },
}),
}
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources(
{
{ name = 'path' }
},
{
{
name = 'cmdline',
option = {
ignore_cmds = { 'Man', '!' }
}
}
})
})
EOF
endif
" luasnip
imap <silent><expr> <Tab> luasnip#expand_or_jumpable() ? '<Plug>luasnip-expand-or-jump' : '<Tab>'
inoremap <silent> <S-Tab> <cmd>lua require'luasnip'.jump(-1)<Cr>
snoremap <silent> <Tab> <cmd>lua require('luasnip').jump(1)<Cr>
snoremap <silent> <S-Tab> <cmd>lua require('luasnip').jump(-1)<Cr>
imap <silent><expr> <C-E> luasnip#choice_active() ? '<Plug>luasnip-next-choice' : '<C-E>'
smap <silent><expr> <C-E> luasnip#choice_active() ? '<Plug>luasnip-next-choice' : '<C-E>'
" cmp - https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance#how-to-add-visual-studio-code-dark-theme-colors-to-the-menu
highlight! CmpItemAbbrDeprecated guibg=NONE gui=strikethrough guifg=#808080
highlight! CmpItemAbbrMatch guibg=NONE guifg=#569CD6
highlight! link CmpItemAbbrMatchFuzzy CmpItemAbbrMatch
highlight! CmpItemKindVariable guibg=NONE guifg=#9CDCFE
highlight! link CmpItemKindInterface CmpItemKindVariable
highlight! link CmpItemKindText CmpItemKindVariable
highlight! CmpItemKindFunction guibg=NONE guifg=#C586C0
highlight! link CmpItemKindMethod CmpItemKindFunction
highlight! CmpItemKindKeyword guibg=NONE guifg=#D4D4D4
highlight! link CmpItemKindProperty CmpItemKindKeyword
highlight! link CmpItemKindUnit CmpItemKindKeyword
" fzf.vim
set rtp+=~/.fzf
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview('up:50%')
\ : fzf#vim#with_preview('right:50%', '?'),
\ <bang>0)
" hop.nvim
if has('nvim')
lua << EOF
require('hop').setup({
quit_key = '<SPC>',
})
local hop = require('hop')
local directions = require('hop.hint').HintDirection
vim.keymap.set('', 'f', function()
hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = true })
end, {remap=true})
vim.keymap.set('', 'F', function()
hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = true })
end, {remap=true})
vim.keymap.set('', 't', function()
hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = true, hint_offset = -1 })
end, {remap=true})
vim.keymap.set('', 'T', function()
hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = true, hint_offset = 1 })
end, {remap=true})
EOF
endif
" nvim-tree.lua
if has('nvim')
lua << EOF
local function open_nvim_tree(data)
-- buffer is a real file on the disk
local real_file = vim.fn.filereadable(data.file) == 1
-- buffer is a [No Name]
local no_name = data.file == "" and vim.bo[data.buf].buftype == ""
-- only files please
if not real_file and not no_name then
return
end
-- open the tree but don't focus it
require("nvim-tree.api").tree.toggle({ focus = false })
end
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })
require'nvim-tree'.setup{
open_on_tab = true,
auto_reload_on_write = true,
update_focused_file = {
enable = true
},
diagnostics = {
enable = false,
},
actions = {
open_file = {
quit_on_open = false,
}
}
}
EOF
endif
" notational-fzf-vim
let g:nv_search_paths = ['~/.notes/']
" vim-gutentags
if s:uname == "Darwin"
let g:gutentags_ctags_executable = '/opt/local/bin/uctags'
elseif s:uname == "Linux"
let g:gutentags_ctags_executable = '/usr/bin/ctags'
endif
let g:gutentags_add_default_project_roots = 0
let g:gutentags_project_root = ['package.json', '.git']
let g:gutentags_cache_dir = expand('~/.gutentags_cache')
let g:gutentags_exclude_filetypes = ['gitcommit', 'gitconfig', 'gitrebase', 'gitsendemail', 'git']
let g:gutentags_trace = 1
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
let g:gutentags_ctags_extra_args = ['--tag-relative=yes', '--fields=+ailmnS']
if executable('rg')
let g:gutentags_file_list_command = 'rg --files'
else
let g:gutentags_file_list_command = {
\ 'markers': {
\ '.git': 'bash -c "git ls-files; git ls-files --others --exclude-standard"',
\ },
\ }
endif
let g:gutentags_ctags_exclude = [
\ '*.git', 'cache', 'build', 'dist', 'bin', 'node_modules',
\ '*.pyc', '.tox', '.mypy_cache',
\ '.DS_Store',
\ '*.bmp', '*.gif', '*.ico', '*.jpg', '*.png', '*.svg',
\ '*.rar', '*.zip', '*.tar', '*.tar.gz', '*.tar.xz', '*.tar.bz2',
\ '*.pdf', '*.doc', '*.docx', '*.ppt', '*.pptx', '*.xls',
\ ]
" vim-template directory
let g:templates_directory="$HOME/.vim/templates"
" vim-indent-guides
let g:indent_guides_enable_on_vim_startup = 1
" vim-move / mini.move
if has('nvim')
lua << EOF
require('mini.move').setup()
EOF
else
let g:move_key_modifier = 'A'
endif
" mini.nvim
if has('nvim')
lua << EOF
require('mini.bufremove').setup()
vim.keymap.set('n', '<leader>Bd', function()
MiniBufremove.delete()
end, { desc = "buffer delete" })
vim.keymap.set('n', '<leader>Bw', function()
MiniBufremove.wipeout()
end, { desc = "buffer wipeout" })
require('mini.cursorword').setup()