-
Notifications
You must be signed in to change notification settings - Fork 184
/
vimrc
executable file
·1400 lines (1206 loc) · 46.8 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
" load plugins
execute pathogen#infect()
call pathogen#helptags()
set nocompatible " be iMproved, required
set nofoldenable " disable folding
filetype off " required
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
"
" Settings
"
set noerrorbells " No beeps
set number " Show line numbers
set backspace=indent,eol,start " Makes backspace key more powerful.
set showcmd " Show me what I'm typing
set noswapfile " Don't use swapfile
set nobackup " Don't create annoying backup files
set nowritebackup
set splitright " Split vertical windows right to the current windows
set splitbelow " Split horizontal windows below to the current windows
set encoding=UTF-8 " Set default encoding to UTF-8
set autowrite " Automatically save before :next, :make etc.
set autoread " Automatically reread changed files without asking me anything
set laststatus=2
set hidden
set ruler " Show the cursor position all the time
au FocusLost * :wa " Set vim to save the file on focus out.
set fileformats=unix,dos,mac " Prefer Unix over Windows over OS 9 formats
set noshowmode " We show the mode with airline or lightline
set incsearch " Shows the match while typing
set hlsearch " Highlight found searches
set ignorecase " Search case insensitive...
set smartcase " ... but not when search pattern contains upper case characters
set ttyfast
" set ttyscroll=3 " noop on linux ?
set lazyredraw " Wait to redraw "
" speed up syntax highlighting
set nocursorcolumn
set nocursorline
syntax sync minlines=256
set synmaxcol=300
set re=1
" do not hide markdown
set conceallevel=0
" open help vertically
command! -nargs=* -complete=help Help vertical belowright help <args>
autocmd FileType help wincmd L
" Make Vim to handle long lines nicely.
set wrap
set textwidth=80
set formatoptions=qrn1
" Do not use relative numbers to where the cursor is.
set norelativenumber
" Apply the indentation of the current line to the next line.
set autoindent
set smartindent
set complete-=i
set showmatch
set smarttab
set tabstop=4
set shiftwidth=4
set expandtab
set nrformats-=octal
set shiftround
" Time out on key codes but not mappings.
" Basically this makes terminal Vim work sanely.
set notimeout
set ttimeout
set ttimeoutlen=10
" By default timeoutlen is 1000 ms
set timeoutlen=500
" have a fixed column for the diagnostics to appear in
" this removes the jitter when warnings/errors flow in
set signcolumn=yes
" Better Completion
set complete=.,w,b,u,t
set completeopt=longest,menuone
if &history < 1000
set history=50
endif
if &tabpagemax < 50
set tabpagemax=50
endif
if !empty(&viminfo)
set viminfo^=!
endif
if !&scrolloff
set scrolloff=1
endif
if !&sidescrolloff
set sidescrolloff=5
endif
set display+=lastline
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" If Linux then set ttymouse
let s:uname = system("echo -n \"$(uname)\"")
if !v:shell_error && s:uname == "Linux" && !has('nvim')
set ttymouse=xterm
endif
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
syntax enable
if has('gui_running')
set transparency=3
" fix js regex syntax
set regexpengine=1
syntax enable
endif
if has('nvim')
let g:tokyonight_style = "night"
let g:tokyonight_italic_functions = 1
let g:tokyonight_transparent = 1
colorscheme tokyonight
else
set background=dark
let g:solarized_termcolors=256
let g:solarized_termtrans=1
colorscheme solarized
endif
set guifont=Inconsolata:h15
set guioptions-=L
" This comes first, because we have mappings that depend on leader
" With a map leader it's possible to do extra key combinations
" i.e: <leader>w saves the current file
let g:mapleader = ","
" ============================= vim-which-key ============================
" Setup WhichKey here for our leader.
" TODO: figure out why the timeout doesn't work
nnoremap <silent> <leader> :<c-u>WhichKey ','<CR>
call which_key#register(',', "g:which_key_map")
" Define prefix dictionary
let g:which_key_map = {}
nnoremap <leader>? :WhichKey ','<CR>
let g:which_key_map['?'] = 'show help'
" This trigger takes advantage of the fact that the quickfix window can be
" easily distinguished by its file-type, qf. The wincmd J command is
" equivalent to the Ctrl+W, Shift+J shortcut telling Vim to move a window to
" the very bottom (see :help :wincmd and :help ^WJ).
autocmd FileType qf wincmd J
" Dont show me any output when I build something
" Because I am using quickfix for errors
"nmap <leader>m :make<CR><enter>
" Replace the current buffer with the given new file. That means a new file
" will be open in a buffer while the old one will be deleted
com! -nargs=1 -complete=file Breplace edit <args>| bdelete #
function! DeleteInactiveBufs()
"From tabpagebuflist() help, get a list of all buffers in all tabs
let tablist = []
for i in range(tabpagenr('$'))
call extend(tablist, tabpagebuflist(i + 1))
endfor
"Below originally inspired by Hara Krishna Dara and Keith Roberts
"http://tech.groups.yahoo.com/group/vim/message/56425
let nWipeouts = 0
for i in range(1, bufnr('$'))
if bufexists(i) && !getbufvar(i,"&mod") && index(tablist, i) == -1
"bufno exists AND isn't modified AND isn't in the list of buffers open in windows and tabs
silent exec 'bwipeout' i
let nWipeouts = nWipeouts + 1
endif
endfor
echomsg nWipeouts . ' buffer(s) wiped out'
endfunction
command! Ball :call DeleteInactiveBufs()
" Close quickfix easily
nnoremap <leader>a :cclose<CR>
let g:which_key_map.a = 'close quickfix'
" Remove search highlight
nnoremap <leader><space> :nohlsearch<CR>
let g:which_key_map['<space>'] = 'remove search highlight'
function! InsertDate()
" Get the position of the cursor, if it is the start of the file we want
" a different behavior than if it is elsewhere.
let cursor_pos = getpos(".")
let now = trim(system('date'))
if cursor_pos[1] == "1"
if cursor_pos[2] == "1"
call append(0, [now, "", "- "])
call cursor(cursor_pos[1]+2, 2)
endif
else
call append(cursor_pos[1], ["", now, "", "- "])
call cursor(cursor_pos[1]+4, 2)
endif
endfunction
" Add a date timestamp between two new lines.
nnoremap <leader>d :call InsertDate()<CR>
let g:which_key_map.d = 'insert date'
" Buffer prev/next
nnoremap <C-x> :bnext<CR>
nnoremap <C-z> :bprev<CR>
" Better split switching
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Fast saving
nmap <leader>w :w!<cr>
let g:which_key_map.w = 'save'
" Fresh vimrc
nnoremap <leader>sv :source $MYVIMRC<CR>
" Center the screen
nnoremap <space> zz
" Move up and down on splitted lines (on small width screens)
map <Up> gk
map <Down> gj
map k gk
map j gj
" Just go out in insert mode
imap jk <ESC>l
" spell check
nnoremap <F6> :setlocal spell! spell?<CR>
" disable the recording macro, drives me nuts.
map q <Nop>
" Search mappings: These will make it so that going to the next one in a
" search will center on the line it's found in.
nnoremap n nzzzv
nnoremap N Nzzzv
" Set the path to where the current file is.
nnoremap <leader>. :lcd %:p:h<CR>
let g:which_key_map['.'] = 'set path as current file'
" When we open vim try and find the project root based on .git.
function! FindGitRoot()
if &buftype ==? ''
" The function doesn't work with autochdir
set noautochdir
" The function only works with local directories
if expand('%:p') =~? '://'
return
endif
" Start in open file's directory
silent! lcd %:p:h
let l:liststart = 0
let l:pattern = '.git'
let l:fullpath = finddir(l:pattern, ';')
" Split the directory into path/match
let l:match = matchstr(l:fullpath, '\m\C[^\/]*$')
let l:path = matchstr(l:fullpath, '\m\C.*\/')
" $HOME + match
let l:home = $HOME . '/' . l:pattern
" If the search hits home try the next item in the list.
" Once a match is found break the loop.
if l:fullpath == l:home
let l:liststart = l:liststart + 1
lcd %:p:h
endif
" If path is anything but blank
if l:path !=? ''
exe 'lcd' . ' ' l:path
endif
if g:root#echo == 1 && l:match !=? ''
echom 'Found' l:match 'in' getcwd()
elseif g:root#echo == 1
echom 'Root dir not found'
endif
endif
endfunction
" Find the git directory root on open of vim.
autocmd BufEnter * silent! FindGitRoot
" Support for sessions, this needs to match the dashboard commands
let g:which_key_map.s = { 'name' : '+session' }
nmap <Leader>ss :<C-u>SessionSave<CR>
let g:which_key_map.s.s = 'session save'
nmap <Leader>sl :<C-u>SessionLoad<CR>
let g:which_key_map.s.l = 'session load'
" Do not show stupid q: window
map q: :q
" Sometimes this happens and I hate it
map :Vs :vs
map :Sp :sp
" dont save .netrwhist history
let g:netrw_dirhistmax=0
" Allow saving of files as sudo when I forgot to start vim using sudo.
cmap w!! w !sudo tee > /dev/null %
" never do this again --> :set paste <ctrl-v> :set no paste
let &t_SI .= "\<Esc>[?2004h"
let &t_EI .= "\<Esc>[?2004l"
inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()
function! XTermPasteBegin()
set pastetoggle=<Esc>[201~
set paste
return ""
endfunction
" Set 80 character line limit
if exists('+colorcolumn')
set colorcolumn=80
else
au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
endif
" ----------------------------------------- "
" File Type settings "
" ----------------------------------------- "
au BufNewFile,BufRead *.vim setlocal noet ts=4 sw=4 sts=4
au BufNewFile,BufRead *.txt setlocal noet ts=4 sw=4
au BufNewFile,BufRead *.md setlocal spell noet ts=4 sw=4
au BufNewFile,BufRead *.yml,*.yaml setlocal expandtab ts=2 sw=2
au BufNewFile,BufRead *.cpp setlocal expandtab ts=2 sw=2
au BufNewFile,BufRead *.hpp setlocal expandtab ts=2 sw=2
au BufNewFile,BufRead *.json setlocal expandtab ts=2 sw=2
au BufNewFile,BufRead *.jade setlocal expandtab ts=2 sw=2
augroup filetypedetect
au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux
au BufNewFile,BufRead .nginx.conf*,nginx.conf* setf nginx
au BufNewFile,BufRead .jinja2* setf jinja
augroup END
au FileType nginx setlocal noet ts=4 sw=4 sts=4
" mutt mail line wrapping
au BufRead /tmp/mutt-* set textwidth=80
" Go settings
au BufNewFile,BufRead *.go setlocal noet ts=4 sw=4 sts=4
" autocmd BufEnter *.go colorscheme nofrils-dark
" scala settings
autocmd BufNewFile,BufReadPost *.scala setl shiftwidth=2 expandtab
" lua settings
autocmd BufNewFile,BufRead *.lua setlocal noet ts=4 sw=4 sts=4
" Dockerfile settings
autocmd FileType dockerfile set noexpandtab
" shell/config/systemd settings
autocmd FileType fstab,systemd set noexpandtab
autocmd FileType gitconfig,sh,toml set noexpandtab
" python indent
autocmd BufNewFile,BufRead *.py setlocal tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80 smarttab expandtab
" For all text files set 'textwidth' to 80 characters.
autocmd FileType text setlocal textwidth=80 fo+=2t ts=2 sw=2 sts=2 expandtab
autocmd BufNewFile,BufRead *.md,*.txt,*.adoc setlocal textwidth=80 fo+=2t ts=2 sw=2 sts=2 expandtab
" toml settings
au BufRead,BufNewFile MAINTAINERS,*.toml set ft=toml formatprg=toml-fmt
au BufRead,BufNewFile Fastfile,Appfile,Podfile set ft=ruby
" hcl settings
au BufRead,BufNewFile *.workflow,*.nomad,*.nomad.tpl set ft=hcl
" mips settings
au BufRead,BufNewFile *.mips set ft=mips
" settings for njk
au BufRead,BufNewFile *.njk,*.hbs set ft=html
" settings for mts
au BufRead,BufNewFile *.mts set ft=typescript
" settings for hujson
au BufRead,BufNewFile *.hujson set ft=json
" settings for kcl
autocmd BufRead,BufNewFile *.kcl set filetype=kcl
" Binary settings: edit binary using xxd-format
augroup Binary
au!
au BufReadPre *.bin let &bin=1
au BufReadPost *.bin if &bin | %!xxd
au BufReadPost *.bin set ft=xxd | endif
au BufWritePre *.bin if &bin | %!xxd -r
au BufWritePre *.bin endif
au BufWritePost *.bin if &bin | %!xxd
au BufWritePost *.bin set nomod | endif
augroup END
" spell check for git commits
autocmd FileType gitcommit setlocal spell
" Wildmenu completion {{{
set wildmenu
" set wildmode=list:longest
set wildmode=list:full
set wildignore+=.hg,.git,.svn " Version control
set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
set wildignore+=*.spl " compiled spelling word lists
set wildignore+=*.sw? " Vim swap files
set wildignore+=*.DS_Store " OSX bullshit
set wildignore+=*.luac " Lua byte code
set wildignore+=migrations " Django migrations
set wildignore+=go/pkg " Go static files
set wildignore+=go/bin " Go bin files
set wildignore+=go/bin-vagrant " Go bin-vagrant files
set wildignore+=*.pyc " Python byte code
set wildignore+=*.orig " Merge resolution files
" ----------------------------------------- "
" Plugin configs "
" ----------------------------------------- "
" ==================== nvim-web-devicons ====================
if has('nvim')
lua << EOF
require'nvim-web-devicons'.setup{
-- globally enable default icons (default to false)
-- will get overriden by `get_icons` option
default = true;
}
EOF
endif
" ==================== telescope.nvim ====================
if has('nvim')
let g:which_key_map.f = { 'name' : '+telescope find' }
nnoremap <leader>ff <cmd>Telescope find_files<CR>
let g:which_key_map.f.f = 'telescope find files'
nnoremap <leader>fg <cmd>Telescope live_grep<CR>
let g:which_key_map.f.g = 'telescope live grep'
nnoremap <leader>fb <cmd>Telescope buffers<CR>
let g:which_key_map.f.b = 'telescope buffers'
nnoremap <leader>fh <cmd>Telescope help_tags<CR>
let g:which_key_map.f.h = 'telescope help tags'
" Make Ctrl-p work for telescope since we know those keybindings so well.
nnoremap <C-p> <cmd>Telescope find_files<CR>
nnoremap <C-g> <cmd>Telescope live_grep<CR>
nnoremap <C-b> <cmd>Telescope git_branches<CR>
if !executable('rg')
echo "You might want to install ripgrep: https://github.com/BurntSushi/ripgrep#installation"
endif
lua << EOF
require('telescope').setup{
defaults = {
mappings = {
i = {
-- map actions.which_key to ?
-- actions.which_key shows the mappings for your picker,
-- e.g. git_{create, delete, ...}_branch for the git_branches picker
["?"] = "which_key"
}
},
file_ignore_patterns = {
"^.git/",
".DS_Store",
},
},
pickers = {
find_files = {
theme = "dropdown",
find_command = {"rg", "--ignore", "--hidden", "--files"},
},
live_grep = {
theme = "dropdown",
},
buffers = {
theme = "dropdown",
},
git_branches = {
theme = "dropdown",
},
},
extensions = {
}
}
EOF
endif
" =================== render-markdown =================
if has('nvim')
lua << EOF
require('render-markdown').setup{
file_types = { 'markdown', 'Avante' },
}
vim.treesitter.language.register('markdown', 'Avante')
EOF
endif
" =================== avante.nvim ======================
if has('nvim')
lua << EOF
require('avante_lib').load()
require('avante').setup{}
EOF
endif
" ==================== nvim-tree.lua ====================
noremap <C-a> :NvimTreeToggle<CR>
let g:which_key_map.n = { 'name' : '+file tree' }
noremap <leader>nn :NvimTreeToggle<cr>
" find the current file in the tree
let g:which_key_map.n.n = 'file tree toggle'
noremap <leader>nf :NvimTreeFindFile<cr>
let g:which_key_map.n.f = 'file tree find file'
if has('nvim')
lua << EOF
--
-- This function has been generated from your
-- view.mappings.list
-- view.mappings.custom_only
-- remove_keymaps
--
-- You should add this function to your configuration and set on_attach = on_attach in the nvim-tree setup call.
--
-- Although care was taken to ensure correctness and completeness, your review is required.
--
-- Please check for the following issues in auto generated content:
-- "Mappings removed" is as you expect
-- "Mappings migrated" are correct
--
-- Please see https://github.com/nvim-tree/nvim-tree.lua/wiki/Migrating-To-on_attach for assistance in migrating.
--
local function on_attach(bufnr)
local api = require('nvim-tree.api')
local function opts(desc)
return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
end
-- Default mappings. Feel free to modify or remove as you wish.
--
-- BEGIN_DEFAULT_ON_ATTACH
vim.keymap.set('n', '<C-]>', api.tree.change_root_to_node, opts('CD'))
vim.keymap.set('n', '<C-e>', api.node.open.replace_tree_buffer, opts('Open: In Place'))
vim.keymap.set('n', '<C-k>', api.node.show_info_popup, opts('Info'))
vim.keymap.set('n', '<C-r>', api.fs.rename_sub, opts('Rename: Omit Filename'))
vim.keymap.set('n', '<C-t>', api.node.open.tab, opts('Open: New Tab'))
vim.keymap.set('n', '<C-v>', api.node.open.vertical, opts('Open: Vertical Split'))
vim.keymap.set('n', '<C-x>', api.node.open.horizontal, opts('Open: Horizontal Split'))
vim.keymap.set('n', '<BS>', api.node.navigate.parent_close, opts('Close Directory'))
vim.keymap.set('n', '<CR>', api.node.open.edit, opts('Open'))
vim.keymap.set('n', '<Tab>', api.node.open.preview, opts('Open Preview'))
vim.keymap.set('n', '>', api.node.navigate.sibling.next, opts('Next Sibling'))
vim.keymap.set('n', '<', api.node.navigate.sibling.prev, opts('Previous Sibling'))
vim.keymap.set('n', '.', api.node.run.cmd, opts('Run Command'))
vim.keymap.set('n', '-', api.tree.change_root_to_parent, opts('Up'))
vim.keymap.set('n', 'a', api.fs.create, opts('Create'))
vim.keymap.set('n', 'bmv', api.marks.bulk.move, opts('Move Bookmarked'))
vim.keymap.set('n', 'B', api.tree.toggle_no_buffer_filter, opts('Toggle No Buffer'))
vim.keymap.set('n', 'c', api.fs.copy.node, opts('Copy'))
vim.keymap.set('n', 'C', api.tree.toggle_git_clean_filter, opts('Toggle Git Clean'))
vim.keymap.set('n', '[c', api.node.navigate.git.prev, opts('Prev Git'))
vim.keymap.set('n', ']c', api.node.navigate.git.next, opts('Next Git'))
vim.keymap.set('n', 'd', api.fs.remove, opts('Delete'))
vim.keymap.set('n', 'D', api.fs.trash, opts('Trash'))
vim.keymap.set('n', 'E', api.tree.expand_all, opts('Expand All'))
vim.keymap.set('n', 'e', api.fs.rename_basename, opts('Rename: Basename'))
vim.keymap.set('n', ']e', api.node.navigate.diagnostics.next, opts('Next Diagnostic'))
vim.keymap.set('n', '[e', api.node.navigate.diagnostics.prev, opts('Prev Diagnostic'))
vim.keymap.set('n', 'F', api.live_filter.clear, opts('Clean Filter'))
vim.keymap.set('n', 'f', api.live_filter.start, opts('Filter'))
vim.keymap.set('n', 'g?', api.tree.toggle_help, opts('Help'))
vim.keymap.set('n', 'gy', api.fs.copy.absolute_path, opts('Copy Absolute Path'))
vim.keymap.set('n', 'H', api.tree.toggle_hidden_filter, opts('Toggle Dotfiles'))
vim.keymap.set('n', 'I', api.tree.toggle_gitignore_filter, opts('Toggle Git Ignore'))
vim.keymap.set('n', 'J', api.node.navigate.sibling.last, opts('Last Sibling'))
vim.keymap.set('n', 'K', api.node.navigate.sibling.first, opts('First Sibling'))
vim.keymap.set('n', 'm', api.marks.toggle, opts('Toggle Bookmark'))
vim.keymap.set('n', 'o', api.node.open.edit, opts('Open'))
vim.keymap.set('n', 'O', api.node.open.no_window_picker, opts('Open: No Window Picker'))
vim.keymap.set('n', 'p', api.fs.paste, opts('Paste'))
vim.keymap.set('n', 'P', api.node.navigate.parent, opts('Parent Directory'))
vim.keymap.set('n', 'q', api.tree.close, opts('Close'))
vim.keymap.set('n', 'r', api.fs.rename, opts('Rename'))
vim.keymap.set('n', 'R', api.tree.reload, opts('Refresh'))
vim.keymap.set('n', 's', api.node.run.system, opts('Run System'))
vim.keymap.set('n', 'S', api.tree.search_node, opts('Search'))
vim.keymap.set('n', 'U', api.tree.toggle_custom_filter, opts('Toggle Hidden'))
vim.keymap.set('n', 'W', api.tree.collapse_all, opts('Collapse'))
vim.keymap.set('n', 'x', api.fs.cut, opts('Cut'))
vim.keymap.set('n', 'y', api.fs.copy.filename, opts('Copy Name'))
vim.keymap.set('n', 'Y', api.fs.copy.relative_path, opts('Copy Relative Path'))
vim.keymap.set('n', '<2-LeftMouse>', api.node.open.edit, opts('Open'))
vim.keymap.set('n', '<2-RightMouse>', api.tree.change_root_to_node, opts('CD'))
-- END_DEFAULT_ON_ATTACH
-- Mappings migrated from view.mappings.list
--
-- You will need to insert "your code goes here" for any mappings with a custom action_cb
vim.keymap.set('n', '?', api.tree.toggle_help, opts('Help'))
vim.keymap.set('n', ':w', api.tree.reload, opts('Refresh'))
vim.keymap.set('n', 'm', api.fs.rename, opts('Rename'))
vim.keymap.set('n', 'r', api.tree.reload, opts('Refresh'))
end
require'nvim-tree'.setup{
on_attach = on_attach,
git = {
ignore = true,
},
-- Setting this to true breaks :GBrowse & vim-rhubarb.
disable_netrw = false,
filters = {
dotfiles = false,
-- TODO: why doesn't this work
custom = {
'.git',
'.DS_Store',
},
},
renderer = {
add_trailing = true,
highlight_opened_files = "icon",
highlight_git = true,
},
view = {
}
}
EOF
endif
" ==================== bufferline.nvim ====================
if has('nvim')
set termguicolors
lua << EOF
require("bufferline").setup{
options = {
diagnostics = "nvim_lsp",
}
}
EOF
endif
" ================== vim-fugitive ====================
" Suggest using pinentry-touchid since it is the least shit option:
" https://github.com/jorgelbg/pinentry-touchid
" This is used when unlocking a gpg key for signing or ssh key for commits.
if !executable('pinentry-touchid') && has('mac')
echo "You might want to install pinentry-touchid: https://github.com/jorgelbg/pinentry-touchid"
endif
let g:which_key_map.g = { 'name' : '+git' }
nnoremap <leader>ga :Git add %:p<CR><CR>
let g:which_key_map.g.a = 'git add current file'
nnoremap <leader>gs :Git<CR>
let g:which_key_map.g.s = 'git status'
nnoremap <leader>gp :Git push<CR><CR>
let g:which_key_map.g.p = 'git push'
nnoremap <leader>gb :Git blame<CR>
let g:which_key_map.g.b = 'git blame'
nnoremap <leader>gc :Git commit -sa<CR><CR>
let g:which_key_map.g.c = 'git commit'
nnoremap <leader>go :GBrowse<CR><CR>
let g:which_key_map.g.o = 'open in GitHub'
" ==================== gitsigns.nvim ====================
if has('nvim')
lua << EOF
require('gitsigns').setup {
signs = {
add = { text = '┃' },
change = { text = '┃' },
delete = { text = '_' },
topdelete = { text = '‾' },
changedelete = { text = '~' },
untracked = { text = '┆' },
},
signcolumn = true, -- Toggle with `:Gitsigns toggle_signs`
numhl = false, -- Toggle with `:Gitsigns toggle_numhl`
linehl = false, -- Toggle with `:Gitsigns toggle_linehl`
word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff`
watch_gitdir = {
follow_files = true
},
auto_attach = true,
attach_to_untracked = false,
current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame`
current_line_blame_opts = {
virt_text = true,
virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align'
delay = 1000,
ignore_whitespace = false,
virt_text_priority = 100,
},
current_line_blame_formatter = '<author>, <author_time:%R> - <summary>',
sign_priority = 6,
update_debounce = 100,
status_formatter = nil, -- Use default
max_file_length = 40000, -- Disable if file is longer than this (in lines)
preview_config = {
-- Options passed to nvim_open_win
border = 'single',
style = 'minimal',
relative = 'cursor',
row = 0,
col = 1
},
}
EOF
endif
" ==================== vim-go ====================
let g:go_fmt_fail_silently = 0
let g:go_fmt_command = "goimports"
let g:go_autodetect_gopath = 1
let g:go_term_enabled = 1
let g:go_snippet_engine = "neosnippet"
let g:go_highlight_space_tab_error = 0
let g:go_highlight_array_whitespace_error = 0
let g:go_highlight_trailing_whitespace_error = 0
let g:go_highlight_extra_types = 0
let g:go_highlight_operators = 0
let g:go_highlight_build_constraints = 1
let g:go_fmt_autosave = 1
au FileType go nmap <Leader>s <Plug>(go-def-split)
au FileType go nmap <Leader>v <Plug>(go-def-vertical)
au FileType go nmap <Leader>i <Plug>(go-info)
au FileType go nmap <Leader>l <Plug>(go-metalinter)
au FileType go nmap <leader>r <Plug>(go-run)
au FileType go nmap <leader>b <Plug>(go-build)
au FileType go nmap <leader>t <Plug>(go-test)
au FileType go nmap <leader>dt <Plug>(go-test-compile)
au FileType go nmap <Leader>d <Plug>(go-doc)
au FileType go nmap <Leader>e <Plug>(go-rename)
" neovim specific
if has('nvim')
au FileType go nmap <leader>rt <Plug>(go-run-tab)
au FileType go nmap <Leader>rs <Plug>(go-run-split)
au FileType go nmap <Leader>rv <Plug>(go-run-vertical)
endif
" I like these more!
augroup go
autocmd!
autocmd Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit')
autocmd Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
autocmd Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
augroup END
" ==================== vim-json ====================
let g:vim_json_syntax_conceal = 0
" ========= vim-better-whitespace ==================
" do not highlight the whitespace
let g:better_whitespace_enabled=1
let g:strip_whitespace_on_save=1
let g:strip_whitespace_confirm=0
" auto strip whitespace except for file with extention blacklisted
let g:better_whitespace_filetypes_blacklist = ['diff', 'git', 'gitcommit', 'unite', 'qf', 'help', 'markdown', 'fugitive', 'rust']
" ========= vim-markdown ==================
" disable folding
let g:vim_markdown_folding_disabled = 1
" Allow for the TOC window to auto-fit when it's possible for it to shrink.
" It never increases its default size (half screen), it only shrinks.
let g:vim_markdown_toc_autofit = 1
" Disable conceal
let g:vim_markdown_conceal = 0
let g:vim_markdown_conceal_code_blocks = 0
" Allow the ge command to follow named anchors in links of the form
" file#anchor or just #anchor, where file may omit the .md extension as usual
let g:vim_markdown_follow_anchor = 1
" highlight frontmatter
let g:vim_markdown_frontmatter = 1
let g:vim_markdown_toml_frontmatter = 1
let g:vim_markdown_json_frontmatter = 1
" =================== lualine.nvim ========================
if has('nvim')
lua << EOF
require('lualine').setup{
options = {
theme = 'tokyonight'
}
}
EOF
endif
" =================== rust.vim ========================
" Enable automatic running of :RustFmt when a buffer is saved.
let g:rustfmt_autosave = 1
let g:rustfmt_autosave_if_config_present = 1
" The :RustPlay command will send the current selection, or if nothing is
" selected the current buffer, to the Rust playpen. Then copy the url to the
" clipboard.
if has('macunix')
let g:rust_clip_command = 'pbcopy'
else
let g:rust_clip_command = 'xclip -selection clipboard'
endif
" =================== vim-terraform ========================
" Allow vim-terraform to override your .vimrc indentation syntax for matching files.
let g:terraform_align=1
" Run terraform fmt on save.
let g:terraform_fmt_on_save=1
" =================== vim-hclfmt ========================
let g:hcl_fmt_autosave = 1
" Ignore terraform since we have the terraform plugin
let g:tf_fmt_autosave = 0
let g:nomad_fmt_autosave = 1
" =================== copilot.vim ========================
hi def CopilotSuggestion guifg=#808080 ctermfg=244
" =================== nvim-lspconfig ========================
if has('nvim-0.5')
" =================== clangd ========================
if executable('clangd')
lua << EOF
require'lspconfig'.clangd.setup{}
EOF
else
echo "You might want to install clangd: https://clangd.llvm.org/installation.html"
endif
" =================== gopls ========================
if executable('gopls')
lua << EOF
require'lspconfig'.gopls.setup{}
EOF
else
echo "You might want to install gopls: https://github.com/golang/tools/tree/master/gopls"
endif
" =================== kcl-lsp ========================
if executable('kcl-language-server')
lua << EOF
local lspconfig = require 'lspconfig'
local configs = require 'lspconfig.configs'
if not configs.kcl_lsp then
configs.kcl_lsp = {
default_config = {
cmd = {'kcl-language-server', 'server', '--stdio'},
filetypes = {'kcl'},
root_dir = lspconfig.util.root_pattern('.git'),
single_file_support = true,
},
docs = {
description = [=[
https://github.com/KittyCAD/kcl-lsp
https://kittycad.io
The KittyCAD Language Server Protocol implementation for the KCL language.
To better detect kcl files, the following can be added:
```
vim.cmd [[ autocmd BufRead,BufNewFile *.kcl set filetype=kcl ]]
```
]=],
default_config = {
root_dir = [[root_pattern(".git")]],
},
}
}
end
lspconfig.kcl_lsp.setup{}
EOF
else
echo "You might want to install kcl-language-server: https://github.com/KittyCAD/kcl-lsp/releases"
endif
" =================== rust-analyzer ========================
if executable('rust-analyzer')
lua << EOF
local nvim_lsp = require'lspconfig'
nvim_lsp.rust_analyzer.setup({
-- on_attach is a callback called when the language server attachs to the buffer
-- on_attach = on_attach,
settings = {
-- config from: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc
["rust-analyzer"] = {
-- enable clippy diagnostics on save
checkOnSave = {
command = "clippy"
},
}
}
})
EOF
else
echo "You might want to install rust-analyzer: https://rust-analyzer.github.io/manual.html#rust-analyzer-language-server-binary"
endif
endif