-
Notifications
You must be signed in to change notification settings - Fork 1
/
vimrc
738 lines (612 loc) · 20.9 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
call plug#begin($DOTDIR . '/vim/plugged')
" Make sure to use single quotes
Plug 'tpope/vim-sensible'
Plug 'vim-pandoc/vim-pandoc'
Plug 'vim-pandoc/vim-pandoc-syntax'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-endwise'
Plug 'thoughtbot/vim-rspec', { 'for': 'ruby' }
" Let vim-closetag work with XSD, XSLT files
let g:closetag_filenames = "*.xml,*.html,*.xsd,*.xsl"
Plug 'alvan/vim-closetag'
Plug 'jiangmiao/auto-pairs'
Plug 'dahu/vim-fanfingtastic'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all --no-update-rc' }
Plug 'junegunn/fzf.vim'
Plug 'tpope/vim-eunuch'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-surround'
Plug 'kana/vim-textobj-user'
Plug 'voldikss/vim-floaterm'
" Bring some of neovim's goodies like focus reporting and cursor shaping to
" terminal vim. Also activates bracketed paste and full mouse support, and
" handles `:checktime` on focus.
Plug 'wincent/terminus'
" Set modern alt/meta mappings: most modern terminals will output Alt-x as Esc-x
" instead of setting the meta bit. This plugin updates Vim's expectations.
"
" In iTerm2, this requires the "Esc+" setting for the Option keys (since Macs
" use Option+key for different characters).
if !has('nvim')
Plug 'drmikehenry/vim-fixkey'
endif
Plug 'szw/vim-maximizer'
Plug 'AndrewRadev/splitjoin.vim'
Plug 'tpope/vim-unimpaired'
Plug 'junegunn/vim-easy-align'
Plug 'mbbill/undotree'
Plug 'tpope/vim-projectionist'
Plug 'williamboman/mason.nvim'
Plug 'williamboman/mason-lspconfig.nvim'
Plug 'simrat39/rust-tools.nvim'
" Improve blockwise copy/paste in Neovim.
" See https://github.com/neovim/neovim/issues/1822
" The issue is fixed for a single running instance, but this plugin still
" helps when pasting between Neovim instances.
Plug 'bfredl/nvim-miniyank'
nmap p <Plug>(miniyank-autoput)
xmap p <Plug>(miniyank-autoput)
nmap P <Plug>(miniyank-autoPut)
xmap P <Plug>(miniyank-autoPut)
nmap - <Plug>(miniyank-cycle)
nmap + <Plug>(miniyank-cycleback)
" When running in the ChromeOS terminal, use OSC52 for copying, but not pasting
if $DISTRO == 'ChromeOS'
lua <<EOF
local function copy(reg)
return require('vim.ui.clipboard.osc52').copy(reg)
end
local function paste()
local lines = vim.fn.split(vim.fn.getreg(''), '\n')
-- Need to use only the first character, because the clipboard
-- integration is unhappy with a regtype like '^V5'
local regtype = vim.fn.getregtype(''):sub(1,1)
return {lines, regtype}
end
vim.g.clipboard = {
name = 'OSC 52',
copy = {
['+'] = copy('+'),
['*'] = copy('*'),
},
paste = {
['+'] = paste,
['*'] = paste,
},
}
EOF
endif
if has('nvim-0.5.0')
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'nvim-treesitter/nvim-treesitter-textobjects'
Plug 'nvim-treesitter/playground'
endif
"""""""""""""
" General "
"""""""""""""
augroup vimrc
" Clear previously-set local autocommands
au!
" Reload vimrc on write
autocmd BufWritePost $MYVIMRC,*/{.,}vimrc :source $MYVIMRC | doauto VimEnter
" Jump to previous cursor location when opening or switching to buffers
autocmd BufReadPost,BufEnter *
\ if &bt !=# 'terminal' && line("'\"") > 0 && line("'\"") < line('$')|
\ exe 'normal g`"' |
\ endif
" Save cursor location when switching away from a buffer
autocmd BufLeave *
\ if &bt !=# 'terminal' |
\ exe 'normal m"' |
\ endif
augroup END
" Set indentation settings
set expandtab " Spaces are used instead of tab characters
set tabstop=8 " This should be 8 for compatibility purposes
set shiftwidth=4 " Shifts (>>, etc.) move by 4 spaces
set softtabstop=-1 " <Tab> inserts {shiftwidth} spaces
" Don't act like sentences end with two spaces.
set nojoinspaces
" Case-insensitive search
set ignorecase
" ...unless we want uppercase
set smartcase
" Highlight search results (can be cleared with Ctrl+L)
set hlsearch
" Cut-and-paste operations use the system clipboard
set clipboard=unnamed,unnamedplus
" Faster update time (pick up changes in vim-gitgutter)
set updatetime=250
" Commandline completion fills in longest common substring, then cycles options
set wildmode=longest:full,full
" Completion won't fill the whole screen
set pumheight=20
" Go to the previous tab instead of the next when closing a tab
augroup vimrc
autocmd TabClosed * :tabprevious
augroup END
" New windows open where expected
set splitbelow splitright
" Terminus handles the FocusGained events, but we also want to check when
" leaving a terminal buffer.
augroup vimrc
autocmd BufEnter * checktime
augroup END
" Allow buffers to stay loaded in the background
set hidden
" Preview substitutions in a split window
set inccommand=split
""""""""""""
" Visual "
""""""""""""
" Turn off all folds by default
set nofoldenable
" Intended folding flow:
" - open a new file, all folds are expanded
" - `zi` to turn on folding at the default level (1)
" - `zM` to close all folds
augroup vimrc
" Folds start off, but leave the first level of folds open if folding is
" switched on. We have to use an autocmd because 'foldlevelstart' is
" also applied when switching to a loaded buffer.
autocmd BufReadPost * setl foldlevel=1
augroup END
set foldtext=MyFoldText()
" Inspired by https://coderwall.com/p/usd_cw/a-pretty-vim-foldtext-function
function! MyFoldText()
let l:padding = &foldcolumn + &number * &numberwidth
" Test if any signs exist
let l:signs = sign_getplaced('%', { 'group': '*' })[0]['signs']
let l:padding += len(l:signs) > 0 ? 2 : 0
let l:windowwidth = winwidth(0) - l:padding
let l:windowwidth = min([l:windowwidth, 100])
let l:starttext = substitute(getline(v:foldstart), '\s*$', '', '')
" Expand tabs (otherwise foldtext will collapse them to one space)
let l:starttext = substitute(l:starttext, '\t', repeat(' ', &tabstop), 'g')
let l:endtext = substitute(getline(v:foldend), '^\s*', '', '')
if v:foldend - v:foldstart > 1
let l:midtext = ' … '
else
let l:midtext = ' '
endif
let l:fulltext = l:starttext . l:midtext . l:endtext
let l:numtext = '[' . (v:foldend - v:foldstart - 1) . ']'
let l:spacesize = l:windowwidth - strwidth(l:fulltext) - strwidth(l:numtext)
" If we have an overflow from two combined lines, just trim the first line
if l:spacesize < 0
let l:numtext = '[' . (v:foldend - v:foldstart) . ']'
let l:fulltextlen = l:windowwidth - strwidth(l:numtext) - 3 " 3 = strwidth(' … ')
let l:fulltext = strcharpart(l:starttext, 0, l:fulltextlen) . ' …'
let l:spacesize = l:windowwidth - strwidth(l:fulltext) - strwidth(l:numtext)
endif
let l:spacetext = repeat(' ', l:spacesize)
return l:fulltext . l:spacetext . l:numtext
endfunction
""""""""""""""
" Filetype "
""""""""""""""
augroup vimrc
" Set fallback omnicompletion
autocmd FileType *
\ if &omnifunc == '' |
\ setlocal omnifunc=syntaxcomplete#Complete |
\ endif
augroup END
augroup vimrc_local
" Clear previously-set local autocommands
au!
"autocmd BufEnter ~/src/tree-sitter-crystal/*.cr let b:ale_fix_on_save=0
autocmd BufEnter ~/src/tree-sitter-crystal/*.js let b:ale_fix_on_save=1 | let b:ale_fixers = ['eslint']
autocmd BufEnter ~/src/tree-sitter-crystal/src/scanner.c,~/src/tree-sitter-crystal/src/unicode.c let b:ale_fix_on_save=1 | let b:ale_fixers = ['clang-format']
" For rendering-api-testing-framework, make sure jest runs with correct
" project options
autocmd BufEnter ~/code/rendering-api-testing-framework/*.js
\ let g:test#javascript#jest#executable = 'npm run test:unit --'
autocmd BufEnter ~/code/browser-testing-framework/*.js
\ let g:test#javascript#mocha#executable = 'npm run test:unit --'
augroup END
""""""""""""
" Syntax "
""""""""""""
vnoremap <Leader>X !xmllint --format --recover -<CR>
""""""""""""""
" Mappings "
""""""""""""""
" Leader
let mapleader = " "
" Quickly edit and source vimrc
nnoremap <Leader>vs :source $MYVIMRC<CR>
nnoremap <Leader>ve :$tabedit ~/.vimrc<CR>
" Let Alt+hjkl act as arrow keys in insert & command-line modes
noremap! <A-j> <Down>
noremap! <A-k> <Up>
noremap! <A-h> <Left>
noremap! <A-l> <Right>
" Don't let autopairs clobber C-h
let g:AutoPairsMapCh = 0
function! g:CheckCmdWin()
return getcmdwintype() !=# ''
endfunction
" Navigate splits
noremap <Leader>j <C-w>j
" The command window is a special case, we can't navigate out and must quit
" instead. This mapping is the only one likely to be called in this case.
noremap <silent> <expr> <Leader>k g:CheckCmdWin() ? ":q\<CR>" : "\<C-w>k"
noremap <Leader>h <C-w>h
noremap <Leader>l <C-w>l
" Same-width/height windows
nnoremap <Leader>nh :leftabove vnew<CR>
nnoremap <Leader>nj :rightbelow new<CR>
nnoremap <Leader>nk :leftabove new<CR>
nnoremap <Leader>nl :rightbelow vnew<CR>
" Full-width/height new windows
nnoremap <Leader>nwh :topleft vnew<CR>
nnoremap <Leader>nwj :botright new<CR>
nnoremap <Leader>nwk :topleft new<CR>
nnoremap <Leader>nwl :botright vnew<CR>
" Faster window resizing
nnoremap <Leader>> :exe "vertical resize " . (winwidth(0) * 4/3)<CR>
nnoremap <Leader>< :exe "vertical resize " . (winwidth(0) * 3/4)<CR>
nnoremap <silent> <M-h> :tabp<CR>
nnoremap <silent> <M-l> :tabn<CR>
" nnoremap gt <Nop>
" nnoremap gT <Nop>
nnoremap <silent> <M-H> :tabm -<CR>
nnoremap <silent> <M-L> :tabm +<CR>
" vim-test mappings
map <silent> <Leader>t :update \| TestFile<CR>
map <silent> <Leader>s :update \| TestNearest<CR>
map <silent> <Leader>r :update \| TestLast<CR>
" Search for visually-selected text
vnoremap / y/\V<C-R>=escape(@",'/\')<CR><CR>
nnoremap zh 5zh
nnoremap zl 5zl
" Make netrw-v open split on the right instead of left
let g:netrw_altv=1
" Split line under cursor (opposite of J)
nnoremap K i<CR><Esc>l
" Remap Ctrl+Slash to comment in insert mode
inoremap <C-_> <C-o>:Commentary<CR>
function! g:EnterWithoutComments()
let l:orig_formatting = &formatoptions
set formatoptions -=r
" Enter insert mode, and perform our <Enter>. :normal implicitly adds
" <Esc> at the end of an insert command, and <Enter><Esc> removes any
" autoindenting, so we insert a dummy space to keep the indent.
execute "normal! a\<CR>\<Space>\<BS>"
let &formatoptions = l:orig_formatting
endfunction
" <Alt-Enter> on a comment line will force the next line to be regular text.
inoremap <silent> <A-CR> <C-c>:call EnterWithoutComments()<CR>I
" fzf mapping
nnoremap <Leader>p :FZF<CR>
nnoremap <Leader>f :Buffers<CR>
" ALE mappings
nmap <silent> [w <Plug>(ale_previous_wrap)
nmap <silent> ]w <Plug>(ale_next_wrap)
" Close extraneous or temporary windows
function! g:CloseExtra()
pclose
cclose
lclose
" helpclose
endfunction
nnoremap <silent> <Leader>w :call g:CloseExtra()<CR>
nnoremap <Leader>W :tabc<CR>
" Clear buffer on ZZ/ZQ
" (double exec avoids using a global variable)
nnoremap <silent> ZZ
\ :exec 'exec "normal! ZZ" \| bd ' . bufnr('%')<CR>
nnoremap <silent> ZQ
\ :exec 'exec "normal! ZQ" \| bd! '. bufnr('%')<CR>
" alias for ZQ that's easier to type for a bunch of buffers in a row
nmap QQ ZQ
nnoremap <Leader>m :MaximizerToggle!<CR>
vnoremap <Leader>m :MaximizerToggle!<CR>gv
" Vim doesn't normally fire events on suspend/resume, so hack around this and
" fire FocusLost/Gained events. Check with `exists` first to avoid a "No
" matching autocommands" message
function! SuspendWithEvents()
if exists('#FocusLost')
doautocmd FocusLost
endif
suspend
if exists('#FocusGained')
doautocmd FocusGained
endif
endfunction
nnoremap <silent> <C-z> :call SuspendWithEvents() <CR>
nnoremap <A-f> :FloatermToggle<CR>
if has('nvim')
tnoremap <silent> <A-f> <C-\><C-n>:FloatermToggle<CR>
tnoremap <Esc> <C-\><C-n>
endif
" After using Fugitive to go back through the git history and inspect
" different commits, this mapping offers a quick way to return to the file
" most recently being worked on. (The alternative is pressing <C-O> an
" arbitrary number of times.)
func! JumpToPrevNonGitBuffer()
let [jumplist, jumpnum] = getjumplist()
let relevant_jumplist = jumplist[:(jumpnum - 1)]
let count=1
for jumpitem in reverse(relevant_jumplist)
if buflisted(jumpitem.bufnr) && bufname(jumpitem.bufnr) !~# "^fugitive://"
execute "normal " . count . "\<c-o>"
return
endif
let count+=1
endfor
endfunc
nnoremap <silent> <Leader>gb :call JumpToPrevNonGitBuffer()<CR>
" Change gitgutter map prefix
xmap <Leader>gs <Plug>(GitGutterStageHunk)
nmap <Leader>gs <Plug>(GitGutterStageHunk)
nmap <Leader>gu <Plug>(GitGutterUndoHunk)
nmap <Leader>gp <Plug>(GitGutterPreviewHunk)
" Show full diffconflict context
nnoremap <Leader>D :DiffConflictsShowHistory<CR>
" Alt-k starts a fzf search for current word
nnoremap <A-k> :Rg <C-r>=expand("<cword>")<CR><CR>
" A nicer version of z=
func! FzfSpellReplace() abort
if !&spell
echohl ErrorMsg
echomsg 'Spell checking is not enabled'
echohl None
return
endif
" TODO: figure out why setting 'window' dict changes the cursor?
call fzf#run({
\ 'source': spellsuggest(expand('<cword>'), 30),
\ 'sink': { word -> execute('normal! ciw'.word) },
\ 'options': ['--prompt', 'Change '''.expand('<cword>').''' to: ', '--no-bold'],
\ 'down': '~30%',
\ })
endfunc
nnoremap <silent> <Leader>z :call FzfSpellReplace()<CR>
" Let Backspace remove the last digit in a partial count
nnoremap <expr> <BS> (v:count ? '<Del>' : '<BS>')
" Use <count><Enter> as a shortcut for :<count><Enter>
nnoremap <expr> <CR> (v:count ? 'G' : '<CR>')
" The indent-blankline plugin doesn't know when folds are revealed, so we need
" to supplement the builtin fold mappings.
" https://github.com/lukas-reineke/indent-blankline.nvim/issues/449
for foldmap in [
\ 'zo',
\ 'zO',
\ 'zc',
\ 'zC',
\ 'za',
\ 'zA',
\ 'zv',
\ 'zx',
\ 'zX',
\ 'zm',
\ 'zM',
\ 'zr',
\ 'zR',
\ 'zn',
\ 'zN',
\ 'zi'
\]
call nvim_set_keymap('n', foldmap, foldmap . '<CMD>IndentBlanklineRefresh<CR>', {
\ 'noremap': v:true,
\ 'silent': v:true,
\ 'desc': 'Fold while refreshing indent guides'})
endfor
" Disable plugin mappings that are covered below
let g:endwise_no_mappings = 1
let g:UltiSnipsRemoveSelectModeMappings = 0
let g:AutoPairsMapCR = 0
let g:UltiSnipsExpandTrigger = '<NUL>'
let g:UltiSnipsListSnippets = '<NUL>'
xmap <Leader>a <Plug>(EasyAlign)
nmap <Leader>a <Plug>(EasyAlign)
" Quick writing
nnoremap <silent> <Leader>w :update<CR>
" Use Ctrl-J/K as alternatives to arrow keys for matching history searches
cnoremap <C-j> <Down>
cnoremap <C-k> <Up>
cnoremap <C-a> <Home>
cnoremap <C-e> <End>
" Avoid Ex mode
nnoremap Q <nop>
"""""""""""""""""""""
" Plugin Settings "
"""""""""""""""""""""
" Options to control vim-plug
" Open diffs in a new tab
let g:plug_pwindow = 'tabe'
" Maximizer settings
" Turn off mappings since we don't want them in insert mode
let g:maximizer_set_default_mapping = 0
" Splitjoin settings
let g:splitjoin_ruby_hanging_args = 0
let g:splitjoin_ruby_options_as_arguments = 1
" Jump to existing window with :Buffers
let g:fzf_buffers_jump = 1
" Define empty heuristics here, other filetype settings may add more.
let g:projectionist_heuristics = {}
runtime! vimrc.d/**/*.vim
call plug#end()
" Use matching colorscheme from terminal theme
if filereadable(expand('~/.vimrc_background'))
if $TERM =~ 'konsole.*'
" No 256 colorspace
set termguicolors
else
let g:base16colorspace=256
let g:base16_shell_path=$DOTDIR . '/base16/base16-shell/scripts'
endif
if $BASE16_THEME =~? 'light'
set background=light
else
set background=dark
endif
source ~/.vimrc_background
endif
lua <<EOF
require'nvim-treesitter.configs'.setup {
ensure_installed = { "hcl" },
highlight = {
enable = true
},
indent = {
enable = true
},
playground = {
enable = true
},
textobjects = {
select = {
enable = true,
-- Automatically jump forward to textobj, similar to targets.vim
lookahead = true,
}
},
}
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.crystal = {
install_info = {
url = "~/src/tree-sitter-crystal", -- local path or git repo
files = {"src/parser.c", "src/scanner.c"},
-- optional entries:
branch = "upstream", -- default branch in case of git repo if different from master
generate_requires_npm = false, -- if stand-alone parser without npm dependencies
requires_generate_from_grammar = false, -- if folder contains pre-generated src/parser.c
},
filetype = "cr", -- if filetype does not match the parser name
}
EOF
lua <<EOF
-- Set up nvim-cmp.
local cmp = require'cmp'
local cmp_ultisnips_mappings = require("cmp_nvim_ultisnips.mappings")
cmp.setup({
snippet = {
expand = function(args)
vim.fn["UltiSnips#Anon"](args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = false }),
["<Tab>"] = cmp.mapping(
function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
cmp_ultisnips_mappings.expand_or_jump_forwards(fallback)
end
end,
{ "i", "s", --[[ "c" (to enable the mapping in command mode) ]] }
),
["<S-Tab>"] = cmp.mapping(
function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
cmp_ultisnips_mappings.jump_backwards(fallback)
end
end,
{ "i", "s", --[[ "c" (to enable the mapping in command mode) ]] }
),
['<C-s>'] = cmp.mapping(
function(fallback)
cmp_ultisnips_mappings.compose { "expand" }(fallback)
end,
{ "i", "s", --[[ "c" (to enable the mapping in command mode) ]] }
)
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'ultisnips' },
{ name = 'path' },
{
name = 'buffer',
option = {
-- Pull suggestions from all buffers
get_bufnrs = function()
return vim.api.nvim_list_bufs()
end
}
},
})
})
-- Enable the following language servers
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
--
-- Add any additional override configuration in the following tables. They will be passed to
-- the `settings` field of the server config. You must look up that documentation yourself.
local servers = {
-- clangd = {},
-- gopls = {},
-- pyright = {},
-- rust_analyzer = {},
-- tsserver = {},
standardrb = {},
ruby_lsp = {},
lua_ls = {
Lua = {
workspace = { checkThirdParty = false },
telemetry = { enable = false },
},
},
}
local on_attach = function(client, bufnr)
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap=true, silent=true, buffer=bufnr }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
vim.keymap.set('n', '<space>d', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
end
-- Set up mason
require("mason").setup()
local mason_lspconfig = require("mason-lspconfig")
mason_lspconfig.setup {
ensure_installed = vim.tbl_keys(servers)
}
-- LSP setup
local lspconfig = require('lspconfig')
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
mason_lspconfig.setup_handlers {
function(server_name)
lspconfig[server_name].setup {
capabilities = capabilities,
settings = servers[server_name],
on_attach = on_attach,
}
end,
["ruby_lsp"] = function()
lspconfig.ruby_lsp.setup {
capabilities = capabilities,
settings = servers.ruby_lsp,
on_attach = on_attach,
init_options = {
formatter = 'standard',
linters = { 'standard' },
},
}
end,
["rust_analyzer"] = function ()
require("rust-tools").setup {
server = {
capabilities = capabilities,
on_attach = on_attach,
}
}
end
}
EOF