forked from nvim-lua/kickstart.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
1084 lines (995 loc) · 38.5 KB
/
Copy pathinit.lua
File metadata and controls
1084 lines (995 loc) · 38.5 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
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
vim.g.have_nerd_font = true
vim.o.number = true
vim.o.mouse = 'a'
vim.o.showmode = false
vim.schedule(function()
-- vim.o.clipboard = 'unnamedplus'
end)
if vim.fn.has 'wsl' == 1 then
vim.opt.runtimepath:append '/home/v006609/.local/share/nvim/site'
vim.g.clipboard = {
name = 'win32yank',
copy = {
['+'] = { 'win32yank.exe', '-i', '--crlf' },
['*'] = { 'win32yank.exe', '-i', '--crlf' },
},
paste = {
['*'] = { 'win32yank.exe', '-o', '--lf' },
['+'] = { 'win32yank.exe', '-o', '--lf' },
},
cache_enabled = 0,
}
end
-- Windows Clipboard Keybinds (WSL)
vim.keymap.set({ 'n', 'v' }, '<leader>y', '"+y', { desc = '[Y]ank to Windows clipboard' })
vim.keymap.set('n', '<leader>Y', '"+Y', { desc = '[Y]ank line to Windows clipboard' })
vim.keymap.set({ 'n', 'v' }, '<leader>p', '"+p', { desc = '[P]aste from Windows clipboard' })
vim.keymap.set({ 'n', 'v' }, '<leader>P', '"+P', { desc = '[P]aste from Windows clipboard (before)' })
vim.o.breakindent = true
vim.o.undofile = true
vim.o.ignorecase = true
vim.o.smartcase = true
vim.o.signcolumn = 'yes'
-- Decrease update time
vim.o.updatetime = 500
-- Decrease mapped sequence wait time
vim.o.timeoutlen = 300
-- Configure how new splits should be opened
vim.o.splitright = true
vim.o.splitbelow = true
-- Sets how neovim will display certain whitespace characters in the editor.
vim.o.list = true
vim.o.inccommand = 'split'
vim.o.cursorline = true
vim.o.scrolloff = 10
-- if performing an operation that would fail due to unsaved changes in the buffer (like `:q`),
-- instead raise a dialog asking if you wish to save the current file(s)
-- See `:help 'confirm'`
vim.o.confirm = true
-- [[ Basic Keymaps ]]
vim.cmd 'packadd nvim.undotree'
vim.keymap.set('n', '<leader>u', require('undotree').open, { desc = '[U]ndotree' })
vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')
vim.keymap.set('n', '\\', ':lua MiniFiles.open()<CR>')
vim.keymap.set('n', '<leader>d', vim.diagnostic.open_float, { desc = 'Show [D]iagnostic floating window' })
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })
vim.keymap.set('n', '<leader>bb', function() require('dap').toggle_breakpoint() end, { desc = 'Debug: Toggle [B]reakpoint' })
vim.keymap.set(
'n',
'<leader>B',
function() require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ') end,
{ desc = 'Debug: Set [B]reakpoint condition' }
)
vim.keymap.set('n', '<leader>bc', function() require('dap').continue() end, { desc = 'Debug: [C]ontinue' })
vim.keymap.set('n', '<leader>bs', function() require('dap').step_over() end, { desc = 'Debug: [S]tep Over' })
vim.keymap.set('n', '<leader>bi', function() require('dap').step_into() end, { desc = 'Debug: Step [I]nto' })
vim.keymap.set('n', '<leader>bo', function() require('dap').step_out() end, { desc = 'Debug: Step [O]ut' })
vim.keymap.set('n', '<leader>bt', function() require('dap').terminate() end, { desc = 'Debug: [T]erminate' })
-- Diagnostic Config & Keymaps
-- See :help vim.diagnostic.Opts
vim.diagnostic.config {
update_in_insert = false,
severity_sort = true,
float = { border = 'rounded', source = 'if_many' },
underline = { severity = { min = vim.diagnostic.severity.WARN } },
-- Can switch between these as you prefer
virtual_text = true, -- Text shows up at the end of the line
virtual_lines = false, -- Text shows up underneath the line, with virtual lines
-- Auto open the float, so you can easily read the errors when jumping with `[d` and `]d`
jump = { float = true },
}
-- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
-- TIP: Disable arrow keys in normal mode
vim.keymap.set('n', '<left>', '<cmd>echo "Use h to move!!"<CR>')
vim.keymap.set('n', '<right>', '<cmd>echo "Use l to move!!"<CR>')
vim.keymap.set('n', '<up>', '<cmd>echo "Use k to move!!"<CR>')
vim.keymap.set('n', '<down>', '<cmd>echo "Use j to move!!"<CR>')
vim.keymap.set('n', '<C-h>', '<C-w><C-h>', { desc = 'Move focus to the left window' })
vim.keymap.set('n', '<C-l>', '<C-w><C-l>', { desc = 'Move focus to the right window' })
vim.keymap.set('n', '<C-j>', '<C-w><C-j>', { desc = 'Move focus to the lower window' })
vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper window' })
vim.keymap.set('n', '>', '<cmd>bnext<CR>', { desc = 'Buffer next' })
vim.keymap.set('n', '<', '<cmd>bprev<CR>', { desc = 'Buffer next' })
vim.o.winborder = 'rounded'
local orig_open = vim.lsp.util.open_floating_preview
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
opts = opts or {}
if opts.border == nil then opts.border = 'rounded' end
return orig_open(contents, syntax, opts, ...)
end
-- Toggle between Java source and test files (like IntelliJ's Ctrl+Shift+T)
local function toggle_java_test()
local file = vim.fn.expand '%:p'
if not file or file == '' then
print 'No file'
return
end
-- Normalize path
local norm = file:gsub('\\', '/')
local alternate
if norm:match '/src/main/java/' then
-- Source -> Test
local test_norm = norm:gsub('/src/main/java/', '/src/test/java/')
local dir = test_norm:match '(.*/)'
local basename = test_norm:match '([^/]+)%.java$'
if not dir or not basename then
print 'Not a Java resource file'
return
end
-- Try common test suffixes
local candidates = {
dir .. basename .. 'Test.java',
}
for _, cand in ipairs(candidates) do
-- convert back to OS-specific separators if you prefer
if vim.fn.filereadable(cand) == 1 then
alternate = cand
break
end
end
if not alternate then alternate = candidates[1] end
elseif norm:match '/src/test/java/' then
-- Test -> Source
local src_norm = norm:gsub('/src/test/java/', '/src/main/java/')
local dir = src_norm:match '(.*/)'
local basename = src_norm:match '([^/]+)%.java$'
if not dir or not basename then
print 'Not a Java test file'
return
end
-- Remove common test suffixes
local bare = basename
bare = bare:gsub('Tests$', '')
bare = bare:gsub('Test$', '')
alternate = dir .. bare .. '.java'
else
print 'Not a Java source or test file'
return
end
if alternate and vim.fn.filereadable(alternate) == 1 then
vim.cmd('edit ' .. vim.fn.fnameescape(alternate))
else
print('Alternate file not found: ' .. (alternate or 'unknown'))
end
end
vim.keymap.set('n', '<leader>tt', toggle_java_test, { desc = '[T]oggle [T]est/Source' })
vim.keymap.set('n', '<leader>jb', '<cmd>JavaBuildBuildWorkspace<CR>', { desc = '[J]ava [B]uild' })
-- Java test keybindings (only set in Java files)
-- Report will auto-show when tests complete (configured in nvim-java setup)
vim.api.nvim_create_autocmd('FileType', {
pattern = 'java',
callback = function()
vim.keymap.set('n', '<leader>tc', '<cmd>JavaTestRunCurrentClass<cr>', { buffer = true, desc = '[T]est [C]urrent Class' })
vim.keymap.set('n', '<leader>tm', '<cmd>JavaTestRunCurrentMethod<cr>', { buffer = true, desc = '[T]est Current [M]ethod' })
vim.keymap.set('n', '<leader>tr', '<cmd>JavaTestViewLastReport<cr>', { buffer = true, desc = '[T]est View Last [R]eport' })
vim.keymap.set('n', '<leader>td', '<cmd>JavaTestDebugCurrentClass<cr>', { buffer = true, desc = '[T]est [D]ebug Current Class' })
-- Keymap to show all Errors in the project in a quickfix list
vim.keymap.set('n', '<leader>be', function()
vim.diagnostic.setqflist { severity = vim.diagnostic.severity.ERROR }
vim.cmd 'copen'
end, { desc = '[B]uild [E]rrors' })
-- Keymap to show all Warnings in the project in a quickfix list
vim.keymap.set('n', '<leader>bw', function()
local all_diags = vim.diagnostic.get() -- alle Buffer/alle Severities
local filtered = {}
for _, d in ipairs(all_diags) do
-- Buffer-Name holen (Dateipfad)
local name = vim.api.nvim_buf_get_name(d.bufnr)
-- Einträge aus target/ überspringen
if not name:match '[/\\]target[/\\]' then
-- in Quickfix-Format umwandeln
table.insert(filtered, {
bufnr = d.bufnr,
lnum = d.lnum + 1,
col = d.col + 1,
text = d.message,
severity = d.severity,
})
end
end
-- Nur Warnungen übernehmen
local qf_items = {}
for _, item in ipairs(filtered) do
if item.severity == vim.diagnostic.severity.WARN then table.insert(qf_items, item) end
end
vim.fn.setqflist({}, ' ', {
title = 'Diagnostics (WARN, ohne target/)',
items = qf_items,
})
vim.cmd.copen()
end, { desc = '[B]uild [W]arnings' })
end,
})
-- [[ Basic Autocommands ]]
-- Deaktiviere Swap für jdt://-Buffer
vim.api.nvim_create_autocmd('BufReadCmd', {
pattern = 'jdt://*',
callback = function() vim.opt_local.swapfile = false end,
})
-- See `:help lua-guide-autocommands`
vim.api.nvim_create_autocmd('FileType', {
pattern = 'java',
callback = function()
-- Nicht auf dekompilierten Library-Klassen ausführen
local bufname = vim.api.nvim_buf_get_name(0)
if vim.startswith(bufname, 'jdt://') then return end
vim.opt_local.expandtab = true
vim.opt_local.shiftwidth = 4
vim.opt_local.tabstop = 4
vim.cmd [[retab]]
end,
})
-- Manual LSP refresh keybind (use when completion stops working)
vim.keymap.set('n', '<leader>lr', function()
-- Detach and re-attach all LSP clients to current buffer
local bufnr = vim.api.nvim_get_current_buf()
for _, client in ipairs(vim.lsp.get_clients { bufnr = bufnr }) do
vim.lsp.buf_detach_client(bufnr, client.id)
vim.lsp.buf_attach_client(bufnr, client.id)
end
print 'LSP clients re-attached'
end, { desc = '[L]SP [R]efresh' })
-- Insert mode: Ctrl+l to force refresh completion
vim.keymap.set('i', '<C-l>', function()
local cmp = require 'cmp'
cmp.close()
vim.schedule(function() cmp.complete() end)
end, { desc = 'Refresh completion' })
-- Highlight when yanking (copying) text
vim.api.nvim_create_autocmd('TextYankPost', {
desc = 'Highlight when yanking (copying) text',
group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
callback = function() vim.hl.on_yank() end,
})
-- [[ Install `lazy.nvim` plugin manager ]]
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 error('Error cloning lazy.nvim:\n' .. out) end
end
---@type vim.Option
local rtp = vim.opt.rtp
rtp:prepend(lazypath)
-- [[ Configure and install plugins ]]
require('lazy').setup({
{ -- Adds git related signs to the gutter, as well as utilities for managing changes
'lewis6991/gitsigns.nvim',
opts = {
signs = {
add = { text = '+' },
change = { text = '~' },
delete = { text = '_' },
topdelete = { text = '‾' },
changedelete = { text = '~' },
},
current_line_blame = true,
current_line_blame_opts = {
delay = 1000,
},
},
keys = {
{ '<leader>gB', function() require('gitsigns').blame() end, desc = '[G]it [B]lame file' },
{ '<leader>gb', function() require('gitsigns').blame_line() end, desc = '[G]it [b]lame line' },
},
},
{ -- Fuzzy Finder (files, lsp, etc)
'nvim-telescope/telescope.nvim',
enabled = true,
event = 'VimEnter',
dependencies = {
'nvim-lua/plenary.nvim',
{ -- If encountering errors, see telescope-fzf-native README for installation instructions
'nvim-telescope/telescope-fzf-native.nvim',
build = 'make',
cond = function() return vim.fn.executable 'make' == 1 end,
},
{ 'nvim-telescope/telescope-ui-select.nvim' },
-- Useful for getting pretty icons, but requires a Nerd Font.
{ 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font },
},
config = function()
require('telescope').setup {
defaults = {
file_ignore_patterns = { 'target/.*', '%.class' },
},
extensions = {
['ui-select'] = {
require('telescope.themes').get_dropdown(),
},
},
}
-- Enable Telescope extensions if they are installed
pcall(require('telescope').load_extension, 'fzf')
pcall(require('telescope').load_extension, 'ui-select')
local builtin = require 'telescope.builtin'
vim.keymap.set('n', '<leader>sh', builtin.help_tags, { desc = '[S]earch [H]elp' })
vim.keymap.set('n', '<leader>sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' })
vim.keymap.set(
'n',
'<leader>sf',
function()
require('telescope.builtin').git_files {
previewer = true,
path_display = { 'filename_first', 'truncate' },
}
end,
{ desc = '[S]earch Git [F]iles' }
)
vim.keymap.set(
'n',
'<leader>sF',
function()
require('telescope.builtin').find_files {
path_display = { 'filename_first', 'truncate' },
}
end,
{ desc = '[S]earch all [F]iles' }
)
vim.keymap.set('n', '<leader>ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' })
vim.keymap.set({ 'n', 'v' }, '<leader>sw', builtin.grep_string, { desc = '[S]earch current [W]ord' })
vim.keymap.set(
'n',
'<leader>sg',
function()
require('telescope.builtin').live_grep {
path_display = { 'filename_first', 'truncate' },
}
end,
{ desc = '[S]earch by [G]rep' }
)
vim.keymap.set('n', '<leader>sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' })
vim.keymap.set('n', '<leader>sr', builtin.resume, { desc = '[S]earch [R]esume' })
vim.keymap.set('n', '<leader>s.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' })
vim.keymap.set('n', '<leader><leader>', builtin.buffers, { desc = '[ ] Find existing buffers' })
-- This runs on LSP attach per buffer (see main LSP attach function in 'neovim/nvim-lspconfig' config for more info,
-- it is better explained there). This allows easily switching between pickers if you prefer using something else!
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('telescope-lsp-attach', { clear = true }),
callback = function(event)
local buf = event.buf
-- Find references for the word under your cursor.
vim.keymap.set(
'n',
'grr',
function()
require('telescope.builtin').lsp_references {
path_display = { 'filename_first', 'truncate' },
}
end,
{ buffer = buf, desc = '[G]oto [R]eferences' }
)
-- maybe fix??
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, { buffer = buf, desc = '[G]oto [I]mplementation' })
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { buffer = buf, desc = '[G]oto [D]efinition' })
-- maybe fix ende !!
-- Jump to the implementation of the word under your cursor.
-- Useful when your language has ways of declaring types without an actual implementation.
-- vim.keymap.set('n', 'gi', builtin.lsp_implementations, { buffer = buf, desc = '[G]oto [I]mplementation' })
-- Jump to the definition of the word under your cursor.
-- This is where a variable was first declared, or where a function is defined, etc.
-- To jump back, press <C-t>.
-- vim.keymap.set('n', 'gd', builtin.lsp_definitions, { buffer = buf, desc = '[G]oto [D]efinition' })
-- Fuzzy find all the symbols in your current document.
-- Symbols are things like variables, functions, types, etc.
vim.keymap.set('n', 'gO', builtin.lsp_document_symbols, { buffer = buf, desc = 'Open Document Symbols' })
-- Fuzzy find all the symbols in your current workspace.
-- Similar to document symbols, except searches over your entire project.
vim.keymap.set('n', 'gW', builtin.lsp_dynamic_workspace_symbols, { buffer = buf, desc = 'Open Workspace Symbols' })
-- Jump to the type of the word under your cursor.
-- Useful when you're not sure what type a variable is and you want to see
-- the definition of its *type*, not where it was *defined*.
vim.keymap.set('n', 'grt', builtin.lsp_type_definitions, { buffer = buf, desc = '[G]oto [T]ype Definition' })
end,
})
-- Override default behavior and theme when searching
vim.keymap.set('n', '<leader>/', function()
-- You can pass additional configuration to Telescope to change the theme, layout, etc.
builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown {
winblend = 10,
previewer = false,
})
end, { desc = '[/] Fuzzily search in current buffer' })
-- It's also possible to pass additional configuration options.
vim.keymap.set(
'n',
'<leader>s/',
function()
builtin.live_grep {
grep_open_files = true,
prompt_title = 'Live Grep in Open Files',
}
end,
{ desc = '[S]earch [/] in Open Files' }
)
-- Shortcut for searching your Neovim configuration files
vim.keymap.set('n', '<leader>sn', function() builtin.find_files { cwd = vim.fn.stdpath 'config' } end, { desc = '[S]earch [N]eovim files' })
end,
},
-- LazyGit plugin
{
'kdheepak/lazygit.nvim',
lazy = true,
cmd = {
'LazyGit',
'LazyGitConfig',
'LazyGitCurrentFile',
'LazyGitFilter',
'LazyGitFilterCurrentFile',
},
-- optional for floating window border decoration
dependencies = {
'nvim-lua/plenary.nvim',
},
-- setting the keybinding for LazyGit with 'keys' is recommended in
-- order to load the plugin when the command is run for the first time
keys = {
{ '<leader>lg', '<cmd>LazyGit<cr>', desc = 'LazyGit' },
},
},
-- LSP Plugins
{
-- Main LSP Configuration
'neovim/nvim-lspconfig',
dependencies = {
-- Automatically install LSPs and related tools to stdpath for Neovim
{ 'mason-org/mason.nvim', opts = {} },
{ 'mason-org/mason-lspconfig.nvim', opts = {} },
'WhoIsSethDaniel/mason-tool-installer.nvim',
{
'nvim-java/nvim-java',
config = function()
require('java').setup {
jdk = {
auto_install = false,
},
root_markers = {
'settings.gradle',
'settings.gradle.kts',
'pom.xml',
'build.gradle',
'mvnw',
'gradlew',
'build.gradle.kts',
'.git',
},
spring_boot_tools = {
enable = true,
},
java_test = {
enable = true,
},
java_debug_adapter = {
enable = true,
},
jdtls = {
java = {
vmargs = {
'-Xms1G',
'-Xmx4G',
'-XX:+UseG1GC',
'-XX:+UseStringDeduplication',
'-XX:MaxMetaspaceSize=1G',
'-XX:ReservedCodeCacheSize=512M',
'-XX:+TieredCompilation',
'-XX:+OptimizeStringConcat',
},
},
settings = {
java = {
fileWatcher = {
enabled = false,
},
-- Enable automatic source download from Maven repositories
maven = {
downloadSources = true,
},
eclipse = {
downloadSources = false,
},
autobuild = {
enabled = false,
},
completion = {
maxResults = 50,
},
import = {
gradle = {
enabled = false,
},
maven = {
enabled = true,
},
},
},
},
},
}
vim.lsp.enable 'jdtls'
-- Handler für dekompilierte Klassen (jdt:// URIs)
vim.lsp.handlers['java/classFileContents'] = function(err, result, ctx)
assert(not err, vim.inspect(err))
if not result then return end
local buf = vim.api.nvim_create_buf(false, true)
local normalized = string.gsub(result, '\r\n', '\n')
local lines = vim.split(normalized, '\n', { plain = true })
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
vim.bo[buf].modifiable = false
vim.bo[buf].filetype = 'java'
vim.api.nvim_win_set_buf(0, buf)
end
-- Auto-show test report when DAP session ends
local dap = require 'dap'
dap.listeners.after.event_terminated['java-test-report'] = function()
local java_test = require 'java-test'
if java_test.last_report then vim.schedule(function()
pcall(function() java_test.last_report:show_report() end)
end) end
end
end,
},
-- Useful status updates for LSP.
-- replaced by snacks.notifier
-- Allows extra capabilities provided by nvim-cmp
'hrsh7th/cmp-nvim-lsp',
},
config = function()
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
callback = function(event)
local map = function(keys, func, desc, mode)
mode = mode or 'n'
vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
end
-- Rename the variable under your cursor.
map('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
-- Execute a code action, usually your cursor needs to be on top of an error
map('<leader>ga', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' })
map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
-- The following two autocommands are used to highlight references of the
-- word under your cursor when your cursor rests there for a little while.
local client = vim.lsp.get_client_by_id(event.data.client_id)
if client and client:supports_method('textDocument/documentHighlight', event.buf) then
local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false })
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
buffer = event.buf,
group = highlight_augroup,
callback = vim.lsp.buf.document_highlight,
})
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
buffer = event.buf,
group = highlight_augroup,
callback = vim.lsp.buf.clear_references,
})
vim.api.nvim_create_autocmd('LspDetach', {
group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }),
callback = function(event2)
vim.lsp.buf.clear_references()
vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf }
end,
})
end
-- The following code creates a keymap to toggle inlay hints in your
-- code, if the language server you are using supports them
if client and client:supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then
map('<leader>th', function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) end, '[T]oggle Inlay [H]ints')
end
end,
})
-- LSP servers and clients are able to communicate to each other what features they support.
-- By default, Neovim doesn't support everything that is in the LSP specification.
-- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities.
-- So, we create new capabilities with cmp-nvim-lsp, and then broadcast that to the servers.
local capabilities = require('cmp_nvim_lsp').default_capabilities()
local servers = {
-- clangd = {},
-- gopls = {},
-- pyright = {},
-- rust_analyzer = {},
ts_ls = {},
stylua = {}, -- Used to format Lua code
-- Special Lua Config, as recommended by neovim help docs
lua_ls = {
on_init = function(client)
if client.workspace_folders then
local path = client.workspace_folders[1].name
if path ~= vim.fn.stdpath 'config' and (vim.uv.fs_stat(path .. '/.luarc.json') or vim.uv.fs_stat(path .. '/.luarc.jsonc')) then return end
end
client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, {
runtime = {
version = 'LuaJIT',
path = { 'lua/?.lua', 'lua/?/init.lua' },
},
workspace = {
checkThirdParty = false,
-- NOTE: this is a lot slower and will cause issues when working on your own configuration.
-- See https://github.com/neovim/nvim-lspconfig/issues/3189
library = vim.tbl_extend('force', vim.api.nvim_get_runtime_file('', true), {
'${3rd}/luv/library',
'${3rd}/busted/library',
}),
},
})
end,
settings = {
Lua = {},
},
},
}
local ensure_installed = vim.tbl_keys(servers or {})
vim.list_extend(ensure_installed, {
'prettier',
})
require('mason-tool-installer').setup { ensure_installed = ensure_installed }
for name, server in pairs(servers) do
vim.lsp.config(name, server)
vim.lsp.enable(name)
end
end,
},
{ -- Autoformat
'stevearc/conform.nvim',
event = { 'BufWritePre' },
cmd = { 'ConformInfo' },
keys = {
{
'<leader>f',
function() require('conform').format { async = true, lsp_format = 'never' } end,
mode = '',
desc = '[F]ormat buffer',
},
},
opts = {
notify_on_error = false,
format_on_save = function(bufnr)
-- Disable "format_on_save lsp_fallback" for languages that don't
-- have a well standardized coding style. You can add additional
-- languages here or re-enable it for the disabled ones.
local disable_filetypes = { c = true, cpp = true, html = true }
if disable_filetypes[vim.bo[bufnr].filetype] then
return nil
else
return {
timeout_ms = 500,
lsp_format = 'never',
}
end
end,
formatters_by_ft = {
lua = { 'stylua' },
javascript = { 'prettier' },
typescript = { 'prettier' },
javascriptreact = { 'prettier' },
typescriptreact = { 'prettier' },
json = { 'prettier' },
css = { 'prettier' },
html = { 'prettier' },
},
formatters = {
['google-java-format'] = {
args = { '--aosp', '-' },
},
},
},
},
{ -- Autocompletion
'hrsh7th/nvim-cmp',
event = 'InsertEnter',
dependencies = {
-- Snippet Engine
{
'L3MON4D3/LuaSnip',
version = '2.*',
build = (function()
if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then return end
return 'make install_jsregexp'
end)(),
dependencies = {
{
'rafamadriz/friendly-snippets',
config = function() require('luasnip.loaders.from_vscode').lazy_load() end,
},
},
opts = {},
},
'saadparwaiz1/cmp_luasnip',
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-path',
'folke/lazydev.nvim',
},
config = function()
local cmp = require 'cmp'
local luasnip = require 'luasnip'
luasnip.config.setup {}
cmp.setup {
snippet = {
expand = function(args) luasnip.lsp_expand(args.body) end,
},
completion = { completeopt = 'menu,menuone,noinsert' },
-- Super-tab style keymaps
mapping = cmp.mapping.preset.insert {
-- Select next/previous item
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-p>'] = cmp.mapping.select_prev_item(),
-- Scroll docs
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
-- Accept completion (Tab to accept, like super-tab)
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.confirm { select = true }
elseif luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
-- Manually trigger completion
['<C-Space>'] = cmp.mapping.complete {},
-- Close completion menu
['<C-e>'] = cmp.mapping.abort(),
},
sources = {
{ name = 'lazydev', group_index = 0 },
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'path' },
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
}
end,
},
--{
-- 'catppuccin/nvim',
-- name = 'catppuccin',
-- priority = 1000,
-- vim.cmd.colorscheme 'catppuccin-mocha',
--},
-- {
-- 'rose-pine/neovim',
-- name = 'rose-pine',
-- priority = 1000,
-- config = function()
-- require('rose-pine').setup {
-- styles = {
-- italic = false,
-- },
-- highlight_groups = {
-- NormalFloat = { bg = 'base' }, -- konsistenter BG aus der Palette
-- FloatBorder = { fg = 'iris', bg = 'base' }, -- Rahmen hebt sich ab
-- },
-- }
-- vim.cmd.colorscheme 'rose-pine'
--
-- -- Semantic-Modifier wieder wie Keywords einfärben
-- vim.api.nvim_set_hl(0, '@lsp.type.modifier', { link = '@keyword' })
-- vim.api.nvim_set_hl(0, '@lsp.type.modifier.java', { link = '@keyword' })
-- end,
-- },
{
'rebelot/kanagawa.nvim',
priority = 1000,
config = function()
require('kanagawa').setup {
keywordStyle = { italic = true },
}
vim.cmd.colorscheme 'kanagawa'
end,
},
-- {
-- 'catppuccin/nvim',
-- priority = 1000, -- Make sure to load this before all the other start plugins.
-- config = function()
-- ---@diagnostic disable-next-line: missing-fields
-- require('catppuccin').setup {
-- flavour = 'mocha',
-- }
-- -- Load the colorscheme here.
-- -- Like many other themes, this one has different styles, and you could load
-- -- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'.
-- vim.cmd.colorscheme 'catppuccin'
-- end,
-- },
-- Highlight todo, notes, etc in comments
{ 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } },
{ -- Snacks.nvim: notifier (replaces fidget.nvim)
'folke/snacks.nvim',
priority = 1000,
lazy = false,
opts = {
notifier = {},
},
config = function(_, opts)
require('snacks').setup(opts)
-- LSP Progress → snacks.notifier (replaces fidget.nvim)
local spinner = { '⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏' }
vim.api.nvim_create_autocmd('LspProgress', {
callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if not client then return end
vim.notify(vim.lsp.status(), 'info', {
id = 'lsp_progress',
title = client.name,
opts = function(notif) notif.icon = ev.data.params.value.kind == 'end' and ' ' or spinner[math.floor(vim.uv.hrtime() / (1e6 * 80)) % #spinner + 1] end,
})
end,
})
end,
},
{ -- Collection of various small independent plugins/modules
'nvim-mini/mini.nvim',
config = function()
-- Better Around/Inside textobjects
--
-- Examples:
-- - va) - [V]isually select [A]round [)]paren
-- - yinq - [Y]ank [I]nside [N]ext [Q]uote
-- - ci' - [C]hange [I]nside [']quote
require('mini.ai').setup { n_lines = 500 }
require('mini.files').setup()
-- Add/delete/replace surroundings (brackets, quotes, etc.)
--
-- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren
-- - sd' - [S]urround [D]elete [']quotes
-- - sr)' - [S]urround [R]eplace [)] [']
-- require('mini.surround').setup()
-- Simple and easy statusline.
-- You could remove this setup call if you don't like it,
-- and try some other statusline plugin
local statusline = require 'mini.statusline'
-- set use_icons to true if you have a Nerd Font
statusline.setup { use_icons = vim.g.have_nerd_font }
-- You can configure sections in the statusline by overriding their
-- default behavior. For example, here we set the section for
-- cursor location to LINE:COLUMN
---@diagnostic disable-next-line: duplicate-set-field
statusline.section_location = function() return '%2l:%-2v' end
-- Show keybindings helper (replaces which-key)
local miniclue = require 'mini.clue'
miniclue.setup {
triggers = {
-- Leader triggers
{ mode = 'n', keys = '<Leader>' },
{ mode = 'x', keys = '<Leader>' },
-- Built-in completion
{ mode = 'i', keys = '<C-x>' },
-- `g` key
{ mode = 'n', keys = 'g' },
{ mode = 'x', keys = 'g' },
-- Marks
{ mode = 'n', keys = "'" },
{ mode = 'n', keys = '`' },
{ mode = 'x', keys = "'" },
{ mode = 'x', keys = '`' },
-- Registers
{ mode = 'n', keys = '"' },
{ mode = 'x', keys = '"' },
{ mode = 'i', keys = '<C-r>' },
{ mode = 'c', keys = '<C-r>' },
-- Window commands
{ mode = 'n', keys = '<C-w>' },
-- `z` key
{ mode = 'n', keys = 'z' },
{ mode = 'x', keys = 'z' },
},
clues = {
-- Enhance this by adding descriptions for <Leader> mapping groups
miniclue.gen_clues.builtin_completion(),
miniclue.gen_clues.g(),
miniclue.gen_clues.marks(),
miniclue.gen_clues.registers(),
miniclue.gen_clues.windows(),
miniclue.gen_clues.z(),
-- Custom leader key groups (matching your which-key spec)
{ mode = 'n', keys = '<Leader>s', desc = '+[S]earch' },
{ mode = 'n', keys = '<Leader>t', desc = '+[T]oggle' },
{ mode = 'n', keys = '<Leader>h', desc = '+Git [H]unk' },
{ mode = 'v', keys = '<Leader>h', desc = '+Git [H]unk' },
{ mode = 'n', keys = '<Leader>l', desc = '+[L]azy' },
{ mode = 'n', keys = '<Leader>j', desc = '+[J]ava' },
{ mode = 'n', keys = '<Leader>b', desc = '+[B]uild' },
},
}
-- ... and there is more!
-- Check out: https://github.com/nvim-mini/mini.nvim
end,
},
{ -- Highlight, edit, and navigate code
'nvim-treesitter/nvim-treesitter',
lazy = false,
build = ':TSUpdate',
branch = 'main',
config = function()
local parsers = {
'bash',
'c',
'diff',