Repository navigation
Expand file tree
/
Copy pathinit.lua
More file actions
1382 lines (1344 loc) · 61.9 KB
/
Copy pathinit.lua
File metadata and controls
1382 lines (1344 loc) · 61.9 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
V = vim ---@diagnostic disable-line
VA = V.api
VC = V.cmd
VD = V.diagnostic
VF = V.fn
VG = V.g
VK = V.keymap.set
VO = V.opt
VG.mapleader = ','
VG.maplocalleader = ' '
VG.python3_host_prog = VF.stdpath('config') .. '/.virtualenv/bin/python'
VG.loaded_perl_provider = 0
VG.loaded_ruby_provider = 0
VO.rtp:append(VF.stdpath('data') .. '/site')
local lazypath = VF.stdpath("data") .. "/lazy/lazy.nvim"
if not V.loop.fs_stat(lazypath) then
VF.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
VO.rtp:prepend(lazypath)
if not VG.vscode then -- Ignore this stuff if I'm running from inside VSCode
require('lazy').setup(
{
{
-- LSP & CMP
'VonHeikemen/lsp-zero.nvim',
branch = 'v4.x',
dependencies = {
{ 'neovim/nvim-lspconfig' },
{ 'williamboman/mason.nvim' },
{ 'williamboman/mason-lspconfig.nvim' },
{ 'hrsh7th/nvim-cmp' },
{ 'hrsh7th/cmp-buffer' },
{ 'hrsh7th/cmp-nvim-lsp' },
{ 'hrsh7th/cmp-nvim-lua' },
{ 'hrsh7th/cmp-path' },
},
config = function()
local lsp = require('lsp-zero')
local lsp_attach = function(_, bufnr)
local o = { buffer = bufnr }
VK('n', '<leader>lD',
'<cmd>lua vim.lsp.buf.declaration()<cr>', o)
VK('n', '<leader>lH',
'<cmd>lua vim.lsp.buf.signature_help()<cr>', o)
VK('n', '<leader>lR',
'<cmd>lua vim.lsp.buf.rename()<cr>', o)
VK('n', '<leader>la',
'<cmd>lua vim.lsp.buf.code_action()<cr>', o)
VK('n', '<leader>ld',
'<cmd>lua vim.lsp.buf.definition()<cr>', o)
VK('n', '<leader>lh',
'<cmd>lua vim.lsp.buf.hover()<cr>', o)
VK('n', '<leader>li',
'<cmd>lua vim.lsp.buf.implementation()<cr>', o)
VK('n', '<leader>lr',
'<cmd>lua vim.lsp.buf.references()<cr>', o)
VK('n', '<leader>lt',
'<cmd>lua vim.lsp.buf.type_definition()<cr>', o)
VK('n', '<leader>lk',
'<cmd>lua vim.diagnostic.goto_prev()<cr>', o)
VK('n', '<leader>lj',
'<cmd>lua vim.diagnostic.goto_next()<cr>', o)
VK('n', '<leader>lo',
'<cmd>lua vim.diagnostic.open_float()<cr>', o)
VK('n', '<leader>lf', '<cmd>LspZeroFormat<cr>', o)
VK('n', '<leader>lW', '<cmd>LspZeroWorkspaceRemove<cr>', o)
VK('n', '<leader>lw', '<cmd>LspZeroWorkspaceAdd<cr>', o)
VK('n', '<leader>ll', '<cmd>LspZeroWorkspaceList<cr>', o)
end
lsp.extend_lspconfig({
capabilities = require(
'cmp_nvim_lsp'
).default_capabilities(),
lsp_attach = lsp_attach,
float_border = 'rounded',
sign_text = true,
})
require('mason').setup({})
require('mason-lspconfig').setup({
ensure_installed = {
'pyright',
},
handlers = {
function(server_name)
require('lspconfig')[server_name].setup({})
end,
}
})
local cmp = require('cmp')
local cmp_format = require('lsp-zero').cmp_format()
-- Single personal snippet source for nvim-cmp.
local my_snippets = {}
function my_snippets.new()
return setmetatable({}, { __index = my_snippets })
end
function my_snippets:complete(_, callback)
callback({
items = {
{
label = 'asb',
kind = vim.lsp.protocol.CompletionItemKind.Snippet,
insertText = '<<ASB: ${1:placeholder text to write}>> ${0}',
insertTextFormat = vim.lsp.protocol.InsertTextFormat.Snippet,
documentation = 'Insert ASB note marker',
},
},
isIncomplete = false,
})
end
cmp.register_source('my_snippets', my_snippets.new())
cmp.setup({
formatting = cmp_format,
snippet = {
expand = function(args)
vim.snippet.expand(args.body)
end,
},
sources = {
{ name = 'my_snippets' },
{ name = 'buffer' },
{ name = 'nvim_lsp' },
{ name = 'nvim_lua' },
{ name = 'path' },
},
view = {
entries = {
name = 'custom',
selection_order = 'near_cursor',
}
},
mapping = cmp.mapping.preset.insert({
['<c-e>'] = V.NIL,
['<C-t>'] = cmp.mapping.complete(),
['<cr>'] = cmp.mapping.confirm({ select = true }),
['<C-c>'] = cmp.mapping.close(),
['<C-d>'] = cmp.mapping.abort(),
['<tab>'] = cmp.mapping.select_next_item(),
['<S-tab>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.scroll_docs(3),
['<C-p>'] = cmp.mapping.scroll_docs(-3),
}),
})
local signs = {
Error = '✘', -- Bold "X" for errors
Warn = '⚐', -- Flag symbol for warnings
Hint = '➔', -- Arrow for hints
Info = '', -- Info symbol as an information icon
}
for type, icon in pairs(signs) do
local hl = 'DiagnosticSign' .. type
VF.sign_define(hl, {
text = icon,
texthl = hl,
numhl = hl,
})
end
local diagnostic_config = {
virtual_text = false,
signs = false,
update_in_insert = false,
underline = false,
severity_sort = true,
float = {
focusable = false,
style = 'minimal',
border = 'rounded',
source = 'always',
header = '',
prefix = '',
},
}
local switch_diagnostics = function(option, state)
if option == 'signs' then
VG.myrc_diagnostics = state
diagnostic_config[option] = VG.myrc_diagnostics
if state == false then
diagnostic_config['virtual_text'] = false
else
diagnostic_config['virtual_text'] =
VG.myrc_diagnostics_vtext
end
VD.config(diagnostic_config)
elseif option == 'virtual_text' then
VG.myrc_diagnostics_vtext = state
diagnostic_config[option] = VG.myrc_diagnostics_vtext
if VG.myrc_diagnostics then
VD.config(diagnostic_config)
end
end
end
local toggle_diagnostics = function()
switch_diagnostics('signs', not VG.myrc_diagnostics)
end
local toggle_diagnostics_vtext = function()
switch_diagnostics('virtual_text',
not VG.myrc_diagnostics_vtext)
end
VG.myrc_diagnostics = false
VG.myrc_diagnostics_vtext = true
switch_diagnostics('signs', VG.myrc_diagnostics)
VK('n', '<leader>vd', toggle_diagnostics)
VK('n', '<leader>vv', toggle_diagnostics_vtext)
lsp.setup()
end,
},
{
-- Fuzzy finder
'nvim-telescope/telescope.nvim',
branch = '0.1.x',
dependencies = { 'nvim-lua/plenary.nvim' },
config = function()
local ac = require('telescope.actions')
local qfix = ac.smart_send_to_qflist + ac.open_qflist
require('telescope').setup({
defaults = {
default_mappings = {
i = {
["<C-/>"] = ac.which_key,
["<C-_>"] = ac.nop,
["<cr>"] = ac.select_default, -- buggy
["<C-e>"] = ac.select_default,
["<C-k>"] = ac.move_selection_previous,
["<C-j>"] = ac.move_selection_next,
["<Tab>"] = ac.move_selection_previous,
["<S-Tab>"] = ac.move_selection_next,
["<Up>"] = ac.move_selection_previous,
["<Down>"] = ac.move_selection_next,
["<C-h>"] = ac.preview_scrolling_down,
["<C-l>"] = ac.preview_scrolling_up,
["<C-m>"] = ac.toggle_selection,
["<C-n>"] = ac.results_scrolling_down,
["<C-p>"] = ac.results_scrolling_up,
["<C-s>"] = ac.select_horizontal,
["<C-t>"] = ac.select_tab,
["<C-v>"] = ac.select_vertical,
["<Esc>"] = ac.close,
["<C-q>"] = qfix,
["<C-w>"] = ac.nop,
["<C-x>"] = ac.nop,
["<M-q>"] = ac.nop,
["<PageDown>"] = ac.nop,
["<PageUp>"] = ac.nop,
},
},
layout_config = {
prompt_position = 'top',
preview_cutoff = 32,
width = 0.9,
height = 0.9,
horizontal = { mirror = false, },
vertical = { mirror = false, },
},
extensions = {
fzf = {
fuzzy = false,
override_generic_sorter = true,
override_file_sorter = true,
case_mode = 'smart_case',
},
},
preview = {
treesitter = false, -- tempfix for upstream bug
}
},
})
require('telescope').load_extension('fzf')
VK('n', '<leader>ff', '<cmd>Telescope git_files<cr>')
VK('n', '<leader>fd', '<cmd>Telescope find_files<cr>')
VK('n', '<leader>fb', '<cmd>Telescope buffers<cr>')
VK('n', '<leader>fh', '<cmd>Telescope help_tags<cr>')
VK('n', '<leader>fr', '<cmd>Telescope oldfiles<cr>')
VK('n', '<leader>fc', '<cmd>Telescope commands<cr>')
VK('n', '<leader>fC', '<cmd>Telescope colorscheme<cr>')
VK('n', '<leader>ft', '<cmd>Telescope tags<cr>')
VK('n', '<leader>f:', '<cmd>Telescope command_history<cr>')
VK('n', '<leader>f/', '<cmd>Telescope search_history<cr>')
VK('n', '<leader>f`', '<cmd>Telescope marks<cr>')
VK('n', '<leader>fq', '<cmd>Telescope quickfix<cr>')
VK('n', '<leader>fQ', '<cmd>Telescope quickfixhistory<cr>')
VK('n', '<leader>fl', '<cmd>Telescope loclist<cr>')
VK('n', '<leader>fj', '<cmd>Telescope jumplist<cr>')
VK('n', '<leader>fo', '<cmd>Telescope vim_options<cr>')
VK('n', '<leader>f@', '<cmd>Telescope registers<cr>')
VK('n', '<leader>f?', '<cmd>Telescope keymaps<cr>')
VK('n', '<leader>fH', '<cmd>Telescope highlights<cr>')
VK('n', '<leader>fR', '<cmd>Telescope resume<cr>')
VK('n', '<leader>fF', '<cmd>Telescope pickers<cr>')
VK('n', '<leader>gc', '<cmd>Telescope git_commits<cr>')
VK('n', '<leader>gC', '<cmd>Telescope git_bcommits<cr>')
VK('n', '<leader>gv', '<cmd>Telescope git_bcommits_range<cr>')
VK('n', '<leader>gb', '<cmd>Telescope git_branches<cr>')
VK('n', '<leader>gs', '<cmd>Telescope git_status<cr>')
VK('n', '<leader>gS', '<cmd>Telescope git_stash<cr>')
VK('n', '<leader>jD', '<cmd>Telescope diagnostics<cr>')
VK('n', '<leader>jr', '<cmd>Telescope lsp_references<cr>')
VK('n', '<leader>jd', '<cmd>Telescope lsp_definitions<cr>')
VK('n', '<leader>jI', '<cmd>Telescope lsp_incoming_calls<cr>')
VK('n', '<leader>jO', '<cmd>Telescope lsp_outgoing_calls<cr>')
VK('n', '<leader>jm', '<cmd>Telescope lsp_implementations<cr>')
VK('n', '<leader>jt', '<cmd>Telescope lsp_type_definitions<cr>')
VK('n', '<leader>jS', '<cmd>Telescope lsp_document_symbols<cr>')
VK('n', '<leader>jw', '<cmd>Telescope lsp_workspace_symbols<cr>')
end,
},
{
-- Telescope FZF
'nvim-telescope/telescope-fzf-native.nvim',
build = 'make'
},
{
-- Treesitter
'nvim-treesitter/nvim-treesitter',
build = ":TSUpdate",
dependencies = 'nvim-treesitter/nvim-treesitter-textobjects',
config = function()
VA.nvim_create_autocmd(
{
'BufEnter', 'BufAdd', 'BufNew',
'BufNewFile', 'BufWinEnter',
},
{
group = VA.nvim_create_augroup(
'TS_FOLD_WORKAROUND', {}
),
callback = function()
VO.foldmethod = 'expr'
VO.foldexpr = 'nvim_treesitter#foldexpr()'
end
}
)
require('nvim-treesitter').setup({
ensure_installed = {
'python',
'bash',
'r',
'lua',
'ocaml',
'javascript',
'typescript',
'commonlisp',
'markdown',
'vimdoc'
},
auto_install = true,
highlight = {
enable = true,
additional_vim_regex_highlighting = { 'markdown' },
},
indent = {
enable = true,
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = '<cr>',
node_incremental = '<cr>',
node_decremental = '<bs>',
scope_incremental = '<S-cr>',
},
},
textobjects = {
select = {
enable = true,
keymaps = {
['af'] = '@function.outer',
['if'] = '@function.inner',
['ac'] = '@class.outer',
['ic'] = '@class.inner',
},
},
move = {
enable = true,
set_jumps = true,
goto_next_start = {
['<leader>nf'] = '@function.outer',
['<leader>nc'] = '@class.outer',
},
goto_next_end = {
['<leader>nF'] = '@function.outer',
['<leader>nC'] = '@class.outer',
},
goto_previous_start = {
['<leader>pf'] = '@function.outer',
['<leader>pc'] = '@class.outer',
},
goto_previous_end = {
['<leader>pF'] = '@function.outer',
['<leader>pC'] = '@class.outer',
},
},
},
})
end,
},
{
-- Hoppity hop
'smoka7/hop.nvim',
version = '*',
config = function()
local hop = require('hop')
local direcn = require('hop.hint').HintDirection
local _f = function()
hop.hint_char1({
direction = direcn.AFTER_CURSOR,
current_line_only = true,
})
end
local _F = function()
hop.hint_char1({
direction = direcn.BEFORE_CURSOR,
current_line_only = true,
})
end
local _t = function()
hop.hint_char1({
direction = direcn.AFTER_CURSOR,
current_line_only = true,
hint_offset = -1,
})
end
local _T = function()
hop.hint_char1({
direction = direcn.BEFORE_CURSOR,
current_line_only = true,
hint_offset = 1,
})
end
require('hop').setup({
keys = 'etovxqpdygfblzhckisuran',
quit_key = '<Esc>',
jump_on_sole_occurrence = true,
case_insensitive = true,
multi_windows = true,
})
VK({ 'n', 'o', 'v' }, 'b', '<cmd>HopChar2<CR>')
VK({ 'n', 'o', 'v' }, '&', '<cmd>HopPattern<CR>')
VK({ 'n', 'o', 'v' }, '_', '<cmd>HopLineStart<CR>')
VK({ 'n', 'o', 'v' }, '<LocalLeader>f', _f)
VK({ 'n', 'o', 'v' }, '<LocalLeader>F', _F)
VK({ 'n', 'o', 'v' }, '<LocalLeader>t', _t)
VK({ 'n', 'o', 'v' }, '<LocalLeader>T', _T)
end,
},
{ -- Search and replace
"roobert/search-replace.nvim",
config = function()
require("search-replace").setup({
default_replace_single_buffer_options = "gcI",
default_replace_multi_buffer_options = "egcI",
})
VK(
"v",
"<leader>rs",
"<CMD>SearchReplaceWithinVisualSelection<CR>",
{}
)
VK(
"v",
"<leader>ro",
"<CMD>SearchReplaceSingleBufferVisualSelection<CR>",
{}
)
VK(
"n",
"<leader>rs",
"<CMD>SearchReplaceSingleBufferOpen<CR>",
{}
)
VK(
"n",
"<leader>ro",
"<CMD>SearchReplaceSingleBufferSelections<CR>",
{}
)
VK(
"n",
"<leader>rO",
"<CMD>SearchReplaceMultiBufferSelections<CR>",
{}
)
VK(
"n",
"<leader>rS",
"<CMD>SearchReplaceMultiBufferOpen<CR>",
{}
)
end,
},
{
-- Zettelkasten
'renerocksai/telekasten.nvim',
config = function()
require('telekasten').setup({
home = VF.expand('~/zettelkasten'),
})
VK("n", "<leader>z", "<cmd>Telekasten panel<CR>")
VK("n", "<leader>z.", "<cmd>Telekasten toggle_todo<CR>")
VK("n", "<leader>zb", "<cmd>Telekasten show_backlinks<CR>")
VK("n", "<leader>zc", "<cmd>Telekasten show_calendar<CR>")
VK("n", "<leader>zf", "<cmd>Telekasten find_notes<CR>")
VK("n", "<leader>zg", "<cmd>Telekasten search_notes<CR>")
VK("n", "<leader>zh", "<cmd>Telekasten show_tags<CR>")
VK("n", "<leader>zi", "<cmd>Telekasten insert_img_link<CR>")
VK("n", "<leader>zl", "<cmd>Telekasten insert_link<CR>")
VK("n", "<leader>zL", "<cmd>Telekasten follow_link<CR>")
VK("n", "<leader>zn", "<cmd>Telekasten new_note<CR>")
VK("n", "<leader>zp", "<cmd>Telekasten preview_image<CR>")
VK("n", "<leader>zr", "<cmd>Telekasten rename_note<CR>")
VK("n", "<leader>zT", "<cmd>Telekasten goto_today<CR>")
VK("n", "<leader>zw", "<cmd>Telekasten goto_thisweek<CR>")
VK("n", "<leader>zy", "<cmd>Telekasten yank_notelink<CR>")
VK("n", "<leader>zt", "<cmd>Telekasten toggle_todo<CR>")
V.treesitter.language.register('markdown', 'telekasten')
end,
dependencies = {
'nvim-telescope/telescope.nvim',
'renerocksai/calendar-vim',
},
},
{
-- REPLs
'jalvesaq/vimcmdline',
config = function()
VG.cmdline_app = {
sh = 'zsh',
python = 'ipy',
julia = 'julia --color=yes',
}
VG.cmdline_vsplit = 1
VG.cmdline_term_height = 50
VG.cmdline_term_width = 120
VG.cmdline_in_buffer = 0
VG.cmdline_map_start = '<LocalLeader>io'
VG.cmdline_map_send = '<LocalLeader>il'
VG.cmdline_map_send_and_stay = '<LocalLeader>is'
VG.cmdline_map_source_fun = '<LocalLeader>if'
VG.cmdline_map_send_paragraph = '<LocalLeader>ip'
VG.cmdline_map_send_block = '<LocalLeader>ib'
VG.cmdline_map_send_motion = '<LocalLeader>im'
VG.cmdline_map_quit = '<LocalLeader>iq'
end,
},
{
-- R REPL :/
'jalvesaq/Nvim-R',
config = function()
VG.R_args = { '--no-save', '--no-restore-data' }
VG.R_assign = 0
VG.R_source = '~/configs/nvim-r-tmux-split.vim'
VG.R_notmux_conf = 1
VG.R_rconsole_width = 120
VG.R_rconsole_height = 0
VG.R_user_maps_only = 1
VC [[
function! s:CustomNvimRMappings()
nmap <buffer> <LocalLeader>io <Plug>RStart
nmap <buffer> <LocalLeader>il <Plug>RSendLine
vmap <buffer> <LocalLeader>is <Plug>RSendSelection
nmap <buffer> <LocalLeader>if <Plug>RSendFunction
nmap <buffer> <LocalLeader>ip <Plug>RSendParagraph
nmap <buffer> <LocalLeader>ib <Plug>RSendBlock
nmap <buffer> <LocalLeader>im <Plug>RSendMotion
nmap <buffer> <LocalLeader>iq <Plug>RClose
endfunction
augroup MyNvimR
autocmd!
autocmd FileType r call s:CustomNvimRMappings()
augroup end
]]
end,
},
{
-- Commenting
'scrooloose/nerdcommenter',
config = function()
VG.NERDRemoveExtraSpaces = 1
VG.NERDSpaceDelims = 1
VG.NERDToggleCheckAllLines = 1
VK({ 'n', 'v' }, '<leader>c ', '<Plug>NERDCommenterToggle')
VK('n', '<leader>cA', '<Plug>NERDCommenterAppend<cr>')
VG.NERDCreateDefaultMappings = 0 -- Doesn't work >.<
VC [[
unmap <leader>c$
unmap <leader>ca
unmap <leader>cb
unmap <leader>cc
unmap <leader>ci
unmap <leader>cl
unmap <leader>cm
unmap <leader>cn
unmap <leader>cs
unmap <leader>cu
unmap <leader>cy
]]
end,
},
{
-- Search in git tree
'mileszs/ack.vim',
config = function()
VG.ackprg = 'rg --vimgrep --no-heading --smart-case'
VC [[
function! FindGitRoot() abort
return system(
\ 'git rev-parse
\ --show-toplevel
\ 2> /dev/null')[:-2]
endfunction
command! -nargs=0 AckCword
\ execute 'Ack! ' .
\ expand('<cword>') . ' ' . FindGitRoot()
command! -nargs=1 AckInput
\ execute 'Ack! <args> ' . FindGitRoot()
]]
VK('n', '<leader>fg', '<cmd>AckCword<cr>')
VK('n', '<leader>fG', ':AckInput ')
end,
},
{
-- Markdown preview
"iamcco/markdown-preview.nvim",
cmd = {
"MarkdownPreviewToggle",
"MarkdownPreview",
"MarkdownPreviewStop",
},
build = "cd app && yarn install",
ft = { "markdown" },
init = function()
VG.mkdp_auto_start = 0
VG.mkdp_auto_close = 0
VG.mkdp_refresh_slow = 1
VG.mkdp_command_for_global = 0
VG.mkdp_open_to_the_world = 0
VG.mkdp_page_title = '「${name}」'
VG.mkdp_filetypes = { 'markdown' }
end
},
{
-- Markdown rendering in Vim
"MeanderingProgrammer/render-markdown.nvim",
dependencies = {
{ "nvim-treesitter/nvim-treesitter" },
{ "echasnovski/mini.icons" },
},
opts = {
file_types = {
'markdown',
'copilot-chat',
'telekasten',
},
latex = { enabled = false },
render_modes = true,
anti_conceal = { enabled = true },
pipe_table = { preset = 'round' },
},
},
{
-- AI - Copilot
'github/copilot.vim',
config = function()
VG.copilot_enabled = (VF.getenv("HAS_GH_COPILOT") == "1") and 1 or 0
VG.copilot_no_tab_map = 1
VK('i', '<C-s>', '<Plug>(copilot-suggest)')
VK('i', '<C-c>', '<Plug>(copilot-dismiss)')
VK('i', '<C-j>', '<Plug>(copilot-next)')
VK('i', '<C-k>', '<Plug>(copilot-previous)')
VK('i', '<C-w>', '<Plug>(copilot-accept-word)')
VK('i', '<C-l>', '<Plug>(copilot-accept-line)')
VK('i', '<C-a>', 'copilot#Accept("\\<CR>")', {
expr = true,
replace_keycodes = false
})
end,
},
{
-- AI - CopilotChat
"CopilotC-Nvim/CopilotChat.nvim",
dependencies = {
{ "github/copilot.vim" },
{ "nvim-lua/plenary.nvim", branch = "master" },
},
build = "make tiktoken",
opts = {
model = 'gpt-4o',
temperature = 0.0,
window = {
layout = "horizontal",
relative = "editor",
width = 1,
height = 0.3,
row = nil,
col = nil,
},
auto_insert_mode = false,
insert_at_end = false,
question_header = "# Me: ",
answer_header = "# Copilot: ",
error_header = "> [!ERROR] Error: ",
separator = "---",
auto_follow_cursor = false,
debug = false,
mappings = {
complete = {
detail = 'Use @<Tab> or /<Tab> for options.',
insert = '<Tab>',
},
close = {
normal = '<Esc>',
insert = '<C-c>'
},
reset = {
normal = '<C-d>',
insert = '<C-d>'
},
submit_prompt = {
normal = '<CR>',
insert = '<C-s>'
},
accept_diff = {
normal = 'da',
},
yank_diff = {
normal = 'dy',
register = '+',
},
jump_to_diff = {
normal = 'dj',
},
quickfix_diffs = {
normal = 'dq',
},
show_diff = {
normal = 'ds'
},
show_info = {
normal = 'di'
},
show_context = {
normal = 'dc'
},
show_help = {
normal = '?'
},
},
},
config = function(_, opts)
local prompts = {
Explain = {
prompt =
'> /COPILOT_EXPLAIN\n\nExplain this code in English focusing on the What, How, and Why in that order.',
description = 'Explain this code in detail',
},
Docstring = {
prompt =
'> /COPILOT_GENERATE\n\nGenerate inline docstrings for this code in English. For python use numpydocstyle. For JS use JSDoc style. For others, pick a similar widely-accepted standard. Also cover exceptions raised.',
description = 'Generate inline docstrings',
},
Test = {
prompt =
'> /COPILOT_GENERATE\n\nWrite unit tests for this code covering all paths. Add tests at the end of the file. For python use pytest. For JS use Jest. For others, pick a similar widely-accepted standard.',
description = 'Write unit tests for the code',
},
Userdoc = {
prompt =
'> /COPILOT_GENERATE\n\nWrite user documentation for this code in English in a helpful and empathetic tone. Include examples and explanations. Explain the defaults, edge cases, possible exceptions. Also add notes, if relevant, about time and space complexity.',
description = 'Write user documentation',
},
Annotate = {
prompt =
'> /COPILOT_GENERATE\n\nAnnotate this code with high quality and comprehensive type hints for all function signatures and variable declarations.',
description = 'Annotate code with type hints',
},
Fixwidth = {
prompt =
'> /COPILOT_GENERATE\n\nResize this code to fit in under 79 columns of width. Do NOT change the contents in any way.',
description = 'Resize code to fit under 79 columns',
},
Review = {
prompt =
'> /COPILOT_REVIEW\n\nReview this code for correctness, style, and performance. Provide feedback in English.',
description = 'Review code for correctness, style, and performance',
},
Fix = {
prompt =
'> /COPILOT_GENERATE\n\nThere is a bug in this code. Identify and rewrite the code to fix it.',
description = 'Identify and fix bugs in the code',
},
CLI = {
prompt =
'> /COPILOT_GENERATE\n\nGenerate a CLI for this code in English. Include options, arguments, default values, and usage instructions. For python use argparse. For JS use yargs. For others, pick a similar widely-accepted standard.',
description = 'Generate a CLI for the code',
},
MakeTable = {
prompt =
'> /COPILOT_GENERATE\n\nConvert this content into a markdown table.',
description = 'Convert to markdown table',
},
MDFormat = {
prompt =
'> /COPILOT_GENERATE\n\nConvert this into a high quality markdown formatted document paying attention to appropriate hierarchical structure markers and other typesetting details. Infer the structure from the content where unclear. Do not edit the content or add any new content.',
description = 'Format as markdown.',
},
}
local chat = require("CopilotChat")
chat.prompts = function()
return prompts
end
local select = require("CopilotChat.select")
local actions = require("CopilotChat.actions")
local ccti = require(
'CopilotChat.integrations.telescope'
)
chat.setup(opts)
opts.selection = function(source)
return select.visual(source) or select.buffer(source)
end
VA.nvim_create_autocmd(
"BufEnter", {
pattern = "copilot-*",
callback = function()
V.opt_local.relativenumber = true
V.opt_local.number = true
local ft = V.bo.filetype
if ft == "copilot-chat" then
V.bo.filetype = "markdown"
end
end,
}
)
VA.nvim_create_user_command(
"CopilotChatVisual",
function(args)
if not chat.chat:visible() then
chat.open()
end
if not chat.chat:focused() then
chat.chat:focus()
end
chat.ask(args.args, { selection = select.visual })
end,
{ nargs = "*", range = true }
)
VA.nvim_create_user_command(
"CopilotChatBuffer",
function(args)
if not chat.chat:visible() then
chat.open()
end
if not chat.chat:focused() then
chat.chat:focus()
end
chat.ask(args.args, { selection = select.buffer })
end,
{ nargs = "*", range = true }
)
VA.nvim_create_user_command(
"CopilotChatPickActionVisual",
function()
ccti.pick(
actions.prompt_actions(
{ selection = select.visual }
)
)
end,
{ nargs = "*", range = true }
)
VA.nvim_create_user_command(
"CopilotChatPickActionBuffer",
function()
ccti.pick(
actions.prompt_actions(
{ selection = select.buffer }
)
)
end,
{ nargs = "*", range = true }
)
end,
keys = {
{
"<LocalLeader>cv",
":CopilotChatVisual<CR>",
mode = "x",
desc = "CopilotChat - Chat over visual selection",
},
{
"<LocalLeader>cb",
":CopilotChatBuffer<CR>",
desc = "CopilotChat - Chat over the buffer contents",
},
{
"<LocalLeader>cp",
":CopilotChatPickActionVisual<CR>",
mode = "v",
desc = "CopilotChat - Pick prompt actions over visual selection",
},
{
"<LocalLeader>cp",
":CopilotChatPickActionBuffer<CR>",
mode = "n",
desc = "CopilotChat - Pick prompt actions over the buffer contents",
},
},
},
{
-- Traverse windows easier
'https://gitlab.com/yorickpeterse/nvim-window.git',
config = function()
require('nvim-window').setup({
chars = {
'e', 't', 'o', 'v', 'x', 'q', 'p', 'd', 'y', 'g',
'f', 'b', 'l', 'z', 'h', 'c', 'k', 'i', 's', 'u',
'r', 'a',
},
normal_hl = 'PmenuSel',
hint_hl = 'Bold',
border = 'double',
})
VK('n', 'ty', require('nvim-window').pick)
end
},
{
-- Wrap arguments and lists
'Wansmer/treesj',
dependencies = { 'nvim-treesitter/nvim-treesitter' },
keys = {
'<LocalLeader>m',
'<LocalLeader>-', -- ignore
'<LocalLeader>_', -- ignore
},
config = function()
require('treesj').setup({
check_syntax_error = true,
max_join_length = 79,
cursor_behavior = 'hold',
notify = true,
dot_repeat = true,
})
end,
},
{
-- Simple file management
'stevearc/oil.nvim',
config = function()
require('oil').setup({
default_file_explorer = true,
columns = {
"icon",
"permissions",
"size",
"mtime",
},
skip_confirm_for_simple_edits = true,
prompt_save_on_select_new_entry = true,
watch_for_changes = true,
use_default_keymaps = false,
keymaps = {
["?"] = "actions.show_help",
["<CR>"] = "actions.select",
["<C-v>"] = {
"actions.select",
opts = { vertical = true },
desc = "Open the entry in a vertical split",
},
["<C-s>"] = {
"actions.select",
opts = { horizontal = true },
desc = "Open the entry in a horizontal split",
},
["<C-t>"] = {
"actions.select",
opts = { tab = true },