-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
1567 lines (1379 loc) · 42.1 KB
/
init.lua
File metadata and controls
1567 lines (1379 loc) · 42.1 KB
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
-- Leader key {{{
-- --------------
-- Since `map` and `remap` evaluate `<leader>` definition eagerly (i.e. not in
-- a lazy manner), we have to set up leader key as soon as possible.
vim.g.mapleader = ' ';
-- }}}
-- Plugins {{{
-- -----------
-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)
require('lazy').setup({
-- Text icons
'kyazdani42/nvim-web-devicons',
-- Fuzzy everything
'nvim-lua/plenary.nvim',
'nvim-telescope/telescope.nvim',
{ 'nvim-telescope/telescope-fzf-native.nvim', build = 'make' },
'nvim-telescope/telescope-project.nvim',
'tami5/sqlite.lua',
-- Modern syntax highlight with `tree-sitter`
{ 'nvim-treesitter/nvim-treesitter', lazy = false, build = ':TSUpdate' },
'nvim-treesitter/playground',
-- Text objects with treesitter
'nvim-treesitter/nvim-treesitter-textobjects',
-- Structural searhc and replace
'cshuaimin/ssr.nvim',
-- Git client
'NeogitOrg/neogit',
-- Code completion frontend with `blink.cmp`
{
"saghen/blink.cmp",
version = "v1.*"
},
-- Debugger
'mfussenegger/nvim-dap',
-- Use a custom statusline
'nvim-lualine/lualine.nvim',
-- Which key
'folke/which-key.nvim',
-- Commenting
'tpope/vim-commentary',
-- Surround
'machakann/vim-sandwich',
-- Sub-word motion
'bkad/CamelCaseMotion',
-- Case coercion
'tpope/vim-abolish',
-- Auto-pairing
'windwp/nvim-autopairs',
-- TeX
'lervag/vimtex',
-- Prettier javascript
{ 'prettier/vim-prettier', build = 'yarn install --frozen-lockfile --production' },
-- Unicode symbols entry
'joom/latex-unicoder.vim',
-- LSP errors
"https://git.sr.ht/~whynothugo/lsp_lines.nvim",
'yorickpeterse/nvim-pqf',
-- Indentation guides
'lukas-reineke/indent-blankline.nvim',
-- Indent level autodetection
'timakro/vim-yadi',
-- Automatically change cwd to the root of the project
'ahmedkhalf/project.nvim',
-- Tree viewer
'MunifTanjim/nui.nvim',
{'nvim-neo-tree/neo-tree.nvim', version = "3.38.0"},
-- REST client
'NTBBloodbath/rest.nvim',
-- Database client
'tpope/vim-dadbod',
'kristijanhusak/vim-dadbod-ui',
'kristijanhusak/vim-dadbod-completion',
-- Live preview commands
'smjonas/live-command.nvim',
-- Theming
'rktjmp/lush.nvim',
'echasnovski/mini.colors',
'ioreshnikov/helix',
{ dir = '~/Code/solarized.nvim/' },
'folke/tokyonight.nvim',
-- Writing mode
'folke/zen-mode.nvim',
})
-- }}}
-- Shortcuts {{{
-- -------------
local function concat(...)
local result = {}
for _, table in ipairs({...}) do
for key, value in pairs(table) do
result[key] = value
end
end
return result
end
local function noremap(opts)
assert(opts.lhs ~= nil)
assert(opts.rhs ~= nil)
return vim.keymap.set(
opts.mode or '', opts.lhs, opts.rhs, {
silent = true,
noremap = true,
desc = opts.desc
}
)
end
local function nnoremap(opts)
return noremap(concat({mode = 'n'}, opts))
end
local function inoremap(opts)
return noremap(concat({mode = 'i'}, opts))
end
local function vnoremap(opts)
return noremap(concat({mode = 'v'}, opts))
end
local function tnoremap(opts)
return noremap(concat({mode = 't'}, opts))
end
-- }}}
-- Evaluating {{{
-- --------------
-- When editing this config we need to re-evaluate parts of it. We define two
-- additional commands. The first one evaluates the current line. The second
-- one -- the active visual selection.
nnoremap { lhs = '<leader>vs', rhs = ':source %<CR>', desc = 'Evaluate buffer' }
vnoremap { lhs = '<leader>vs', rhs = 'y:@"<CR>', desc = 'Evaluate selection' }
-- }}}
-- Use mouse {{{
-- -------------
vim.opt.mouse = 'a'
-- }}}
-- Use system clipboard {{{
-- ------------------------
vim.opt.clipboard = 'unnamedplus'
-- }}}
-- Scroll {{{
-- ----------
-- I love when there's a bit of space between the current line and the end of
-- the window. 5 lines feels like sweet spot.
vim.opt.scrolloff=5
-- }}}
-- Backups {{{
-- -----------
-- Didn't really have to use the backups once, but always annoyed by seeing the
-- files on disk.
vim.opt.backup = false
vim.opt.writebackup = false
vim.opt.swapfile = false
-- }}}
-- Automatic file reload {{{
-- -------------------------
-- trigger `autoread` when files changes on disk
vim.opt.autoread = true
vim.api.nvim_command([[
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI *
\ if mode() != 'c' |
\ checktime |
\ endif
]])
-- notification after file change
vim.api.nvim_command([[
autocmd FileChangedShellPost * echo "File changed on disk. Buffer reloaded."
]])
-- }}}
-- Case sensitivity {{{
-- --------------------
-- I don't really care about case sensitivity when searching.
vim.opt.ignorecase = true
vim.opt.smartcase = true
-- }}}
-- Line numbers and sign column {{{
-- --------------------------------
-- For buffers that correspond to a file on disk I'd like to see relative line
-- numbers and a sign column. The latter might not have a practical use for
-- files not associated with an LSP server, but I like it purely for
-- aesthetic reasons.
vim.api.nvim_command([[
function EnableSignColumn() abort
setlocal signcolumn=yes:2
endfunction
function EnableLineNumbers() abort
setlocal number
setlocal relativenumber
endfunction
function EnableEditingHelpers() abort
setlocal numberwidth=5
setlocal colorcolumn=80
call EnableLineNumbers()
call EnableSignColumn()
endfunction
autocmd BufReadPost,BufNewFile * call EnableEditingHelpers()
]])
-- " }}}
-- Current line {{{
-- ----------------
-- I like to see the current line to be highlighted
vim.opt.cursorline = true
-- }}}
-- Whitespace {{{
-- --------------
-- Show whitespace characters
vim.opt.listchars.extend = 'tab:→ ,trail:⋅'
-- Try to autodect indent level when a file is open
vim.api.nvim_command([[autocmd BufRead * DetectIndent]])
-- Otherwise use filetype specific
-- filetype plugin indent on
-- As a fallback, indent by 4 spaces
vim.opt.expandtab = true
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
-- Automatically remove trailing whitespace when saving the file
vim.api.nvim_command([[autocmd BufWritePre * :%s/\s\+$//e]])
-- }}}
-- Wrap {{{
-- --------
-- Break at a "breakeable" character when soft-wrapping lines.
vim.opt.linebreak = true
vim.opt.textwidth = 0
vim.opt.wrapmargin = 0
vim.opt.showbreak='⤷ '
-- By default we do not wrap, but that can be overriden in some buffers
vim.opt.wrap = false
vim.opt.linebreak = true
-- }}}
-- Folds {{{
-- ---------
-- Folds are occasionally useful. I wish I could use tree-sitter aware folds,
-- but as of now they're glitchy and tend to randomly collapse when you edit a
-- region. Therefore I resort to good old fold by marker.
vim.opt.foldmethod = 'expr'
vim.opt.foldexpr = "v:lua.vim.treesitter.foldexpr()"
vim.opt.foldtext = ""
vim.opt.foldlevel = 99
-- }}}
-- Movement in tabs and splits {{{
-- -------------------------------
-- `vim` has a quite powerful window system, but the default keybindings make
-- you a bit slow when using it. Here are more conventional ones.
-- Quick navigation between the tabs
noremap { lhs = '<C-t>', rhs = ':tabnew<CR>' }
noremap { lhs = '<C-w>', rhs = ':tabclose<CR>'}
tnoremap { lhs = '<C-t>', rhs = '<C-\\><C-n>:tabnew<CR>' }
tnoremap { lhs = '<C-w>', rhs = '<C-\\><C-n>:tabclose<CR>' }
noremap { lhs = '<A-1>', rhs = '1gt' }
noremap { lhs = '<A-2>', rhs = '2gt' }
noremap { lhs = '<A-3>', rhs = '3gt' }
noremap { lhs = '<A-4>', rhs = '4gt' }
noremap { lhs = '<A-5>', rhs = '5gt' }
noremap { lhs = '<A-6>', rhs = '6gt' }
noremap { lhs = '<A-7>', rhs = '7gt' }
noremap { lhs = '<A-8>', rhs = '8gt' }
noremap { lhs = '<A-9>', rhs = '9gt' }
tnoremap { lhs = '<A-1>', rhs = '<C-\\><C-n>1gt' }
tnoremap { lhs = '<A-2>', rhs = '<C-\\><C-n>2gt' }
tnoremap { lhs = '<A-3>', rhs = '<C-\\><C-n>3gt' }
tnoremap { lhs = '<A-4>', rhs = '<C-\\><C-n>4gt' }
tnoremap { lhs = '<A-5>', rhs = '<C-\\><C-n>5gt' }
tnoremap { lhs = '<A-6>', rhs = '<C-\\><C-n>6gt' }
tnoremap { lhs = '<A-7>', rhs = '<C-\\><C-n>7gt' }
tnoremap { lhs = '<A-8>', rhs = '<C-\\><C-n>8gt' }
tnoremap { lhs = '<A-9>', rhs = '<C-\\><C-n>9gt' }
-- " Quick navigation between the splits
noremap { lhs = '<A-v>', rhs = ':vsp<CR>' }
noremap { lhs = '<A-s>', rhs = ':split<CR>' }
noremap { lhs = '<A-q>', rhs = ':close<CR>' }
noremap { lhs = '<A-o>', rhs = ':only<CR>' }
tnoremap { lhs = '<A-v>', rhs = '<C-\\><C-n>:vsp<CR>' }
tnoremap { lhs = '<A-s>', rhs = '<C-\\><C-n>:split<CR>' }
tnoremap { lhs = '<A-q>', rhs = '<C-\\><C-n>:close<CR>' }
tnoremap { lhs = '<A-o>', rhs = '<C-\\><C-n>:only<CR>' }
noremap { lhs = '<A-h>', rhs = '<C-w>h' }
noremap { lhs = '<A-j>', rhs = '<C-w>j' }
noremap { lhs = '<A-k>', rhs = '<C-w>k' }
noremap { lhs = '<A-l>', rhs = '<C-w>l' }
tnoremap { lhs = '<A-h>', rhs = '<C-\\><C-n><C-w>h' }
tnoremap { lhs = '<A-j>', rhs = '<C-\\><C-n><C-w>j' }
tnoremap { lhs = '<A-k>', rhs = '<C-\\><C-n><C-w>k' }
tnoremap { lhs = '<A-l>', rhs = '<C-\\><C-n><C-w>l' }
-- }}}
-- Movement on wrapped lines {{{
-- -----------------------------
-- I am using soft line-wrap everywhere. The default navigation commands in vim
-- work on physical lines, not wrapped ones. This is really inconvenient. This
-- should fix it.
vim.api.nvim_command([[
nnoremap <silent> <expr> j v:count ? 'j' : !&wrap ? 'j' : 'gj'
nnoremap <silent> <expr> k v:count ? 'k' : !&wrap ? 'k' : 'gk'
nnoremap <silent> <expr> ^ v:count ? '^' : !&wrap ? '^' : 'g^'
nnoremap <silent> <expr> 0 v:count ? '0' : !&wrap ? '0' : 'g0'
nnoremap <silent> <expr> $ v:count ? '$' : !&wrap ? '$' : 'g$'
vnoremap <silent> <expr> j v:count ? 'j' : !&wrap ? 'j' : 'gj'
vnoremap <silent> <expr> k v:count ? 'k' : !&wrap ? 'k' : 'gk'
vnoremap <silent> <expr> ^ v:count ? '^' : !&wrap ? '^' : 'g^'
vnoremap <silent> <expr> 0 v:count ? '0' : !&wrap ? '0' : 'g0'
vnoremap <silent> <expr> $ v:count ? '$' : !&wrap ? '$' : 'g$'
]])
-- }}}
-- Automatically set cwd {{{
-- -------------------------
do
local defaults = require('project_nvim.config').defaults
require('project_nvim').setup {
detection_methods = { "pattern" },
patterns = {
'tsconfig.json',
'main/',
unpack(defaults.patterns)
},
scope_chdir = 'tab'
}
end
-- }}}
-- Telescope {{{
-- -------------
local telescope = require('telescope')
local actions = require('telescope.actions')
local sorters = require('telescope.sorters')
telescope.setup {
defaults = {
border = true,
file_ignore_patterns = {
'__pycache__/',
'%.pyc',
'node_modules/',
'target/',
'gen/'
},
layout_strategy = 'bottom_pane',
layout_config = {
height = 0.5,
prompt_position = 'top',
},
prompt_prefix = ' ',
prompt_title = true,
sorter = sorters.get_fzy_sorter,
sorting_strategy = 'ascending',
winblend = 5,
},
extensions = {
fzf = {
fuzzy = true,
override_generic_sorter = true,
override_file_sorter = true
},
project = {
base_dirs = {
{ '~/Code/', max_depth = 3 },
{ vim.fn.stdpath('data') .. '/lazy', max_depth = 2 },
{ '~/.config/nvim' }
},
make_display = function (project)
local displayer = require("telecope.pickers.entry_display").create {
separator = " ",
items = {
{ width = 1},
{ width = 64 },
{ width = 0 }
}
}
return displayer {
{ " " },
{ project.title },
{ project.display_path }
}
end
}
},
pickers = {
buffers = {
ignore_current_buffer = true,
sort_lastused = true,
mappings = {
n = {
['d'] = actions.delete_buffer
},
i = {
['<C-d>'] = actions.delete_buffer
},
}
}
}
}
telescope.load_extension('project')
telescope.load_extension('fzf')
noremap {
lhs = '<leader>ff',
rhs = require('telescope.builtin').find_files,
desc = 'Files'
}
noremap {
lhs = '<leader>fb',
rhs = function ()
require('telescope.builtin').buffers({ show_all_buffers = true })
end,
desc = 'Buffers'
}
noremap {
lhs = '<leader>b',
rhs = require('telescope.builtin').buffers,
desc = 'Buffers'
}
noremap {
lhs = '<leader>fg',
rhs = require('telescope.builtin').live_grep,
desc = 'Grep'
}
noremap {
lhs = '<leader>fG',
rhs = function ()
return require('telescope.builtin').live_grep({ grep_open_files = true })
end,
desc = 'Grep open files'
}
noremap {
lhs = '<leader>fh',
rhs = require('telescope.builtin').oldfiles,
desc = 'History'
}
noremap {
lhs = '<leader>fm',
rhs = require('telescope.builtin').marks,
desc = 'Marks'
}
noremap {
lhs = '<leader>fp',
rhs = require('telescope').extensions.project.project,
desc = 'Project'
}
noremap {
lhs = '<leader>fr',
rhs = require('telescope.builtin').resume,
desc = 'Resume'
}
vim.api.nvim_command([[hi link TelescopeNormal NormalFloat]])
vim.api.nvim_command([[hi link TelescopeBorder NormalFloat]])
vim.api.nvim_command([[hi link TelescopePromptPrefix Comment]])
vim.api.nvim_command([[hi link TelescopeTitle Ignore]])
-- }}}
-- Which key {{{
-- -------------
do
local wk = require('which-key')
wk.setup({
preset = "classic",
delay = 1000,
icons = {
mappings = false,
colors = false,
breadcrumbs = ">",
separator = "->",
group = ""
},
layout = {
spacing = 10
},
win = {
border = "rounded",
wo = {
winblend = 5
}
}
})
wk.add({
{ "<leader>g", group = "Git/" },
{ "<leader>e", group = "Diagnostics/" },
{ "<leader>f", group = "Telescope/" },
{ "<leader>fs", group = "Bolt/" },
{ "<leader>l", group = "Link/" },
{ "<leader>r", group = "REST/" },
{ "<leader>s", group = "Swap/" },
{ "<leader>t", group = "Terminal/" },
{ "<leader>v", group = "Evaluate/" },
{ "<leader>db", group = "Database/" },
})
end
-- }}}
-- Command line {{{
-- ----------------
-- -- It's possible now to hide command line and it looks neat!
vim.opt.cmdheight = 0
-- -- Except that it doesn't show you when you're recording a macro
vim.api.nvim_command([[autocmd CmdlineEnter * set cmdheight=1]])
vim.api.nvim_command([[autocmd CmdlineLeave * set cmdheight=0]])
vim.api.nvim_command([[autocmd RecordingEnter * set cmdheight=1]])
vim.api.nvim_command([[autocmd RecordingLeave * set cmdheight=0]])
-- }}}
-- Status line {{{
-- ---------------
do
local filename = require('lualine.components.filename'):extend()
filename.apply_icon = require('lualine.components.filetype').apply_icon
local modesymbol = {
['NORMAL'] = ' NOR',
['INSERT'] = ' INS',
['VISUAL'] = ' VIS',
['V-LINE'] = ' VIS',
['V-BLOCK'] = ' VIS',
['TERMINAL'] = ' ZSH',
['COMMAND'] = ' CMD',
}
local function mode()
local mode = require('lualine.utils.mode').get_mode()
local symb = modesymbol[mode]
if symb == nil then
return mode
else
return symb
end
end
require('lualine').setup {
options = {
component_separators = '',
section_separators = '',
disabled_filetypes = {},
globalstatus = false
},
sections = {
lualine_a = {
{
mode,
padding = { left = 2, right = 2 }
},
},
lualine_b = {
{
filename,
padding = { left = 2, right = 2 }
},
},
lualine_c = {
'progress',
'location',
},
lualine_x = {
'branch',
'fileformat',
'encoding',
},
lualine_y = {
{
'diagnostics',
colored = false,
padding = { left = 2, right = 1 }
},
},
lualine_z = {
{
'filetype',
colored = false,
padding = { left = 2, right = 2 }
},
}
},
inactive_sections = {
lualine_a = {},
lualine_b = {
{
filename,
padding = { left = 2, right = 2 }
}
},
lualine_c = {},
lualine_x = {},
lualine_y = {},
lualine_z = {}
}
}
end
-- }}}
-- Indentation guide {{{
-- ---------------------
-- XXX: The usability is sadly not that great due to a long-standing bug in
-- neovim:
-- https://github.com/neovim/neovim/issues/6591
-- The setup is minimalistic -- I mostly disable the indentation guides in the
-- modes I don't want them to see.
require('ibl').setup {
indent = { char = '▏' },
exclude = {
filetypes = {
'help',
'markdown',
'neo-tree',
'TelescopePrompt',
'tex',
'toggleterm',
}
},
scope = {
enabled = false
}
}
-- }}}
-- Neogit {{{
-- ----------
require('neogit').setup({
kind = "replace",
disable_hint = true,
filewatcher = { enabled = false },
signs = {
hunk = { "▶", "▼" },
item = { "▶", "▼" },
section = { "▶", "▼" },
},
})
nnoremap { lhs = '<leader>gg', rhs = ':Neogit<CR>', desc = 'Neogit' }
-- }}}
-- Tree sitter {{{
-- ---------------
-- The section below configures `tree-sitter` to be used for syntax
-- highlighting, selection, indentation and automatic delimiters pairing.
require('nvim-treesitter.configs').setup {
ensure_installed = 'all',
ignore_install = {'phpdoc', 'ipkg'},
highlight = {
enable = true,
additional_vim_regex_highlighting = {'org'}
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = 'gnn',
node_incremental = 'grn',
scope_incremental = 'grc',
node_decremental = 'grm'
}
},
indent = {
enable = true,
disable = { 'python' }
},
textobjects = {
select = {
enable = true,
lookahead = true,
keymaps = {
["ia"] = "@parameter.inner",
["aa"] = "@parameter.outer",
["if"] = "@function.inner",
["af"] = "@function.outer",
["ic"] = "@class.inner",
["ac"] = "@class.outer",
},
},
swap = {
enable = true,
swap_next = {
["<leader>sa"] = "@parameter.inner"
},
swap_previous = {
["<leader>sA"] = "@parameter.inner"
}
},
move = {
enable = true,
set_jumps = true,
goto_next_start = {
["]a"] = "@parameter.inner",
["]f"] = "@function.outer",
["]c"] = "@class.outer",
},
goto_next_end = {
["]A"] = "@parameter.outer",
["]F"] = "@function.outer",
["]C"] = "@class.outer",
},
goto_previous_start = {
["[a"] = "@parameter.inner",
["[f"] = "@function.outer",
["[c"] = "@class.outer",
},
goto_previous_end = {
["[A"] = "@parameter.outer",
["[F"] = "@function.outer",
["[C"] = "@class.outer",
}
}
},
playground = {
enable = true
}
}
-- NOTE: about `ignore_install` above: I want to use treesitter for everything,
-- but I want to stick to stable grammar files. Until April 2022 it was
-- possible to do this with setting `ensure_installed = 'maintained'`. Since
-- April 2022 'maintained' was marked as deprecated and I switched to 'all'.
-- Some of the grammars in 'all' are occasionally broken. One of them is
-- 'phpdoc', but the list will surely grow.
-- }}}
-- Structural search and replace {{{
-- -----------------------------
noremap { mode = {'n', 'v'}, lhs = '<leader>ssr', rhs = require('ssr').open }
-- }}}
-- Subword navigation {{{
-- ----------------------
-- This is a really cool plugin that allow one to navigate based on a subword,
-- i.e. it treats 'Camel' and 'Case' in 'CamelCase', 'snake' and 'case' in
-- 'snake_case' and 'kebab' and 'case' in 'kebab-case' as separate words.
vim.api.nvim_command([[
map <silent> w <Plug>CamelCaseMotion_w
map <silent> b <Plug>CamelCaseMotion_b
map <silent> e <Plug>CamelCaseMotion_e
map <silent> ge <Plug>CamelCaseMotion_ge
sunmap w
sunmap b
sunmap e
sunmap ge
omap <silent> iw <Plug>CamelCaseMotion_iw
xmap <silent> iw <Plug>CamelCaseMotion_iw
omap <silent> ib <Plug>CamelCaseMotion_ib
xmap <silent> ib <Plug>CamelCaseMotion_ib
omap <silent> ie <Plug>CamelCaseMotion_ie
xmap <silent> ie <Plug>CamelCaseMotion_ie
imap <silent> <S-Left> <C-o><Plug>CamelCaseMotion_b
imap <silent> <S-Right> <C-o><Plug>CamelCaseMotion_w
]])
-- " }}}
-- Emacs-like motion keys in insert mode {{{
-- -------------------------------------
inoremap { lhs = '<C-e>', rhs = '<C-o>$' }
inoremap { lhs = '<C-a>', rhs = '<C-o>0' }
inoremap { lhs = '<C-f>', rhs = '<C-o>l' }
inoremap { lhs = '<C-b>', rhs = '<C-o>h' }
inoremap { lhs = '<C-n>', rhs = '<C-o>j' }
inoremap { lhs = '<C-p>', rhs = '<C-o>k' }
inoremap { lhs = '<M-f>', rhs = '<C-o><Plug>CamelCaseMotion_w' }
inoremap { lhs = '<M-b>', rhs = '<C-o><Plug>CamelCaseMotion_b' }
-- }}}
-- Code completion {{{
-- -------------------
-- Completion backend is handed by the LSP servers of choice. We configure them
-- in the corresponding language section. UI is provided by nvim-cmp.
vim.opt.pumheight = 16
vim.opt.pumwidth = 32
vim.opt.pumblend = 5
vim.opt.completeopt = {'menu', 'menuone', 'noselect'}
require('blink.cmp').setup({
completion = {
menu = { winblend = 5, draw = { columns = { {'label'}, {'kind_icon', 'kind', gap = 1} } } },
documentation = { auto_show = true },
ghost_text = { enabled = false }
},
signature = { enabled = true },
keymap = {
['<Tab>'] = { 'select_next', 'fallback' },
['<S-Tab>'] = { 'select_prev', 'fallback' },
['<CR>'] = { 'accept', 'fallback' }
},
sources = {
default = {'lsp', 'path', 'snippets'},
per_filetype = {
sql = { 'dadbod', 'lsp', 'path', 'snippets' },
mysql = { 'dadbod', 'lsp', 'path', 'snippets' },
plsql = { 'dadbod', 'lsp', 'path', 'snippets' }
},
providers = {
dadbod = {
name = 'Dadbod',
module = 'vim_dadbod_completion.blink'
}
}
},
})
-- Debugging with DAP {{{
-- ----------------------
-- General settings
require('dap')
vim.fn.sign_define(
'DapBreakpoint', {
text = ' ',
texthl = 'DiagnosticError',
linehl = '',
numhl = 'DiagnosticError'
})
vim.fn.sign_define(
'DapBreakpointCondition', {
text = ' ',
texthl = 'DiagnosticWarning',
linehl = '',
numhl = 'DiagnosticWarning'
})
vim.fn.sign_define(
'DapBreakpointRejected', {
text = ' ',
texthl = 'Comment',
linehl = '',
numhl = 'Comment'
})
vim.fn.sign_define(
'DapStopped', {
text = ' ',
texthl = 'DiagnosticHint',
linehl = '',
numhl = 'DiagnosticHint'
})
-- Commands
vim.api.nvim_command('command! DapClearBreakpoints lua require("dap").clear_breakpoints()<CR>')
-- Keybindings
nnoremap { lhs = '<F5>', rhs = ':DapContinue<CR>' }
nnoremap { lhs = '<F9>', rhs = ':DapToggleBreakpoint<CR>' }
nnoremap { lhs = '<F10>', rhs = ':DapStepOver<CR>' }
nnoremap { lhs = '<F11>', rhs = ':DapStepInto<CR>' }
-- }}}
-- Automatic delimiter pairing {{{
-- -------------------------------
require('nvim-autopairs').setup {}
-- }}}
-- General LSP setup {{{
-- ---------------------
local signs = {
Error = '',
Warn = '',
Hint = '',
Info = '',
}
for type, icon in pairs(signs) do
local hl = 'DiagnosticSign' .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = 'LineNr' })
end
local on_attach = function(client, buffer)
vim.api.nvim_buf_set_keymap(
buffer,
'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>',
{ noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(
buffer,
'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>',
{ noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(
buffer,
'n', 'gtd', '<cmd>lua vim.lsp.buf.type_definition()<CR>',
{ noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(
buffer,
'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>',
{ noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(
buffer,
'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>',
{ noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(
buffer,
'n', '<leader>la', '<cmd>lua vim.lsp.buf.code_action()<CR>',
{ noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(
buffer,
'n', '<leader>lr', '<cmd>lua vim.lsp.buf.rename()<CR>',
{ noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(
buffer,
'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>',
{ noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(
buffer,
'n', 'ge', '<cmd>lua vim.diagnostic.open_float({ scope = "line" })<CR>',
{ noremap = true, silent = true })
-- Hide all semantic highlights
for _, group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
vim.api.nvim_set_hl(0, group, {})
end
if client.server_capabilities.inlayHintProvider then
vim.lsp.inlay_hint.enable(true)
end
client.server_capabilities.semanticTokensProvider = nil
end
vim.api.nvim_command('command! LspGotoDeclaration lua vim.lsp.buf.declaration()<CR>')
vim.api.nvim_command('command! LspGotoDefinition lua vim.lsp.buf.definition()<CR>')
vim.api.nvim_command('command! LspHover lua vim.lsp.buf.hover()<CR>')
vim.api.nvim_command('command! LpsGotoImplementation lua vim.lsp.buf.implentation()<CR>')
vim.api.nvim_command('command! LspSignature lua vim.lsp.buf.signature_help()<CR>')
vim.api.nvim_command('command! LspRename lua vim.lsp.buf.rename()<CR>')
vim.api.nvim_command('command! LspCodeAction lua vim.lsp.buf.code_action()<CR>')
-- }}}
-- Error diagnostics {{{