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
986 lines (850 loc) · 32.9 KB
/
init.lua
File metadata and controls
986 lines (850 loc) · 32.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
-- This is a fork of Kickstart.nvim
-- Set <space> as the leader key
-- See `:help mapleader`
-- NOTE: Must happen before plugins are required (otherwise wrong leader will be used)
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
-- [[ Install `lazy.nvim` plugin manager ]]
-- https://github.com/folke/lazy.nvim
-- `:help lazy.nvim.txt` for more info
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
vim.fn.system {
'git',
'clone',
'--filter=blob:none',
'https://github.com/folke/lazy.nvim.git',
'--branch=stable', -- latest stable release
lazypath,
}
end
vim.opt.rtp:prepend(lazypath)
-- NOTE: You should make sure your terminal supports this
-- Setting this early for plugins that need it (like colorizer)
vim.o.termguicolors = true
require('lazy').setup({
-- NOTE: First, some plugins that don't require any configuration
-- Tim Pope essentials
'tpope/vim-surround',
'tpope/vim-repeat', -- Enable repeating supported plugin maps with "."
-- AI autocomplete: Codeium
{
'Exafunction/codeium.vim',
event = 'BufEnter',
config = function()
-- Disable default bindings and keep explicit keymaps.
vim.g.codeium_disable_bindings = 1
vim.keymap.set('i', '<C-g>', function() return vim.fn['codeium#Accept']() end, { expr = true, silent = true })
vim.keymap.set('i', '<C-]>', function() return vim.fn['codeium#CycleCompletions'](1) end, { expr = true, silent = true })
vim.keymap.set('i', '<M-[>', function() return vim.fn['codeium#CycleCompletions'](-1) end, { expr = true, silent = true })
vim.keymap.set('i', '<C-x>', function() return vim.fn['codeium#Clear']() end, { expr = true, silent = true })
end,
},
-- Navigation within files - Hop (the community favorite EasyMotion replacement)
{
"phaazon/hop.nvim",
branch = 'v2',
config = function()
local hop = require('hop')
hop.setup { keys = 'etovxqpdygfblzhckisuran' }
-- Custom highlights with cyan background
vim.api.nvim_set_hl(0, 'HopNextKey', { bg = '#00dfff', fg = '#000000', bold = true })
vim.api.nvim_set_hl(0, 'HopNextKey1', { bg = '#00dfff', fg = '#000000', bold = true })
vim.api.nvim_set_hl(0, 'HopNextKey2', { bg = '#ff007c', fg = '#000000', bold = true })
vim.api.nvim_set_hl(0, 'HopUnmatched', { fg = '#666666' })
-- Hop to any character (most used)
vim.keymap.set('n', 's', function() hop.hint_char1() end, {desc = "Hop to character"})
-- Hop to any word beginning
vim.keymap.set('n', 'gw', function() hop.hint_words() end, {desc = "Hop to word"})
-- Hop with 2 characters for precision (shift-s)
vim.keymap.set('n', 'S', function() hop.hint_char2() end, {desc = "Hop to 2 characters"})
end,
},
-- Better search highlighting and preview
{
"kevinhwang91/nvim-hlslens",
config = function()
require('hlslens').setup()
-- Show search count in virtual text
local kopts = {noremap = true, silent = true}
vim.api.nvim_set_keymap('n', 'n', [[<Cmd>execute('normal! ' . v:count1 . 'n')<CR><Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('n', 'N', [[<Cmd>execute('normal! ' . v:count1 . 'N')<CR><Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('n', '*', [[*<Cmd>lua require('hlslens').start()<CR>]], kopts)
vim.api.nvim_set_keymap('n', '#', [[#<Cmd>lua require('hlslens').start()<CR>]], kopts)
end,
},
-- Quick file switching
{
"ThePrimeagen/harpoon",
branch = "harpoon2",
dependencies = { "nvim-lua/plenary.nvim" },
config = function()
local harpoon = require("harpoon")
harpoon:setup()
-- Set up keybindings after harpoon is loaded
vim.keymap.set("n", "<leader>ha", function() harpoon:list():add() end, { desc = "Harpoon add file" })
vim.keymap.set("n", "<leader>hh", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end, { desc = "Harpoon menu" })
vim.keymap.set("n", "<leader>1", function() harpoon:list():select(1) end, { desc = "Harpoon file 1" })
vim.keymap.set("n", "<leader>2", function() harpoon:list():select(2) end, { desc = "Harpoon file 2" })
vim.keymap.set("n", "<leader>3", function() harpoon:list():select(3) end, { desc = "Harpoon file 3" })
vim.keymap.set("n", "<leader>4", function() harpoon:list():select(4) end, { desc = "Harpoon file 4" })
end,
},
-- Tree view for file structure
-- Detect tabstop and shiftwidth automatically
'tpope/vim-sleuth',
-- Visual undo history
{
'mbbill/undotree',
config = function()
vim.keymap.set('n', '<leader>u', vim.cmd.UndotreeToggle, { desc = 'Toggle [U]ndo tree' })
end
},
'hashivim/vim-terraform',
-- "Just works" IDE features
{
'NvChad/nvim-colorizer.lua',
opts = {
user_default_options = {
mode = "background",
tailwind = true,
},
}
},
{
"folke/todo-comments.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
opts = {
-- No config needed, just works!
}
},
{
"RRethy/vim-illuminate",
config = function()
-- Automatically highlights other uses of word under cursor
require('illuminate').configure({
delay = 100,
large_file_cutoff = 2000,
})
end
},
{
"hedyhli/outline.nvim",
config = function()
require("outline").setup({
-- Ensure j/k work normally
outline_window = {
wrap = false,
show_cursorline = true,
hide_cursor = false,
},
})
vim.keymap.set('n', '<leader>o', ':Outline<CR>', { desc = 'Toggle symbols [o]utline' })
end
},
{
'stevearc/oil.nvim',
opts = {
-- Skip confirmation for simple edits
skip_confirm_for_simple_edits = true,
-- Delete to trash instead of permanently
delete_to_trash = true,
-- Show more file information
columns = {
"icon",
"permissions",
"size",
"mtime",
},
-- Watch for external file changes
watch_for_changes = true,
-- View options
view_options = {
show_hidden = true,
},
},
dependencies = { "nvim-tree/nvim-web-devicons" },
},
-- NOTE: This is where your plugins related to LSP can be installed.
-- The configuration is done below. Search for lspconfig to find it below.
{
-- LSP Configuration & Plugins
'neovim/nvim-lspconfig',
dependencies = {
-- Automatically install LSPs to stdpath for neovim
'williamboman/mason.nvim',
'williamboman/mason-lspconfig.nvim',
-- Useful status updates for LSP
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
{ 'j-hui/fidget.nvim', opts = {} },
-- Lua dev experience for Neovim config and plugin authoring.
{
'folke/lazydev.nvim',
ft = 'lua',
opts = {
library = {
{ path = '${3rd}/luv/library', words = { 'vim%.uv' } },
},
},
},
},
},
{
'saghen/blink.cmp',
version = '*',
event = 'InsertEnter',
opts = {
keymap = { preset = 'default' },
completion = { documentation = { auto_show = true } },
sources = {
default = { 'lsp', 'path', 'snippets', 'buffer' },
},
},
opts_extend = { 'sources.default' },
},
-- Useful plugin to show you pending keybinds.
{ 'folke/which-key.nvim', opts = {} },
{
-- Adds git related signs to the gutter, as well as utilities for managing changes
'lewis6991/gitsigns.nvim',
opts = {
-- See `:help gitsigns.txt`
signs = {
add = { text = '+' },
change = { text = '~' },
delete = { text = '_' },
topdelete = { text = '‾' },
changedelete = { text = '~' },
},
on_attach = function(bufnr)
vim.keymap.set('n', '<leader>hp', require('gitsigns').preview_hunk, { buffer = bufnr, desc = 'Preview git hunk' })
-- don't override the built-in and fugitive keymaps
local gs = package.loaded.gitsigns
vim.keymap.set({ 'n', 'v' }, ']c', function()
if vim.wo.diff then
return ']c'
end
vim.schedule(function()
gs.next_hunk()
end)
return '<Ignore>'
end, { expr = true, buffer = bufnr, desc = 'Jump to next hunk' })
vim.keymap.set({ 'n', 'v' }, '[c', function()
if vim.wo.diff then
return '[c'
end
vim.schedule(function()
gs.prev_hunk()
end)
return '<Ignore>'
end, { expr = true, buffer = bufnr, desc = 'Jump to previous hunk' })
end,
},
},
-- {
-- "bluz71/vim-nightfly-colors",
-- priority = 1000, -- load this before all other start plugins
-- name = "nightfly",
-- config = function()
-- vim.cmd.colorscheme 'nightfly'
-- end,
-- },
-- {
-- "rhysd/vim-color-spring-night",
-- priority = 1000, -- load this before all other start plugins
-- name = "spring-night",
-- config = function()
-- vim.cmd.colorscheme 'spring-night'
-- end,
-- },
{
-- Set lualine as statusline
'nvim-lualine/lualine.nvim',
-- See `:help lualine.txt`
config = function()
require('lualine').setup({
options = {
icons_enabled = false,
theme = 'flexoki',
component_separators = '|',
section_separators = '',
globalstatus = true, -- Single status line for all windows
always_divide_middle = false,
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = {
{
'filename',
path = 1, -- relative path
symbols = {
modified = ' [+]',
readonly = ' [RO]',
unnamed = '[No Name]',
},
}
},
lualine_x = {'encoding', 'fileformat', 'filetype'},
lualine_y = {'progress'},
lualine_z = {'location'}
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {{'filename', path = 1}},
lualine_x = {'location'},
lualine_y = {},
lualine_z = {}
},
winbar = {},
inactive_winbar = {},
tabline = {
lualine_a = {},
lualine_b = {},
lualine_c = {
{
function()
local filepath = vim.fn.expand('%:p')
if filepath == '' then
return '[No Name]'
end
return filepath
end,
color = { fg = '#ffffff', bg = '#1a1a1a', gui = 'bold' },
}
},
lualine_x = {
{
function()
return 'CWD: ' .. vim.fn.getcwd()
end,
color = { fg = '#00a0ff', bg = '#1a1a1a', gui = 'bold' },
}
},
lualine_y = {},
lualine_z = {}
},
})
end,
},
{
-- Add indentation guides even on blank lines
'lukas-reineke/indent-blankline.nvim',
-- Enable `lukas-reineke/indent-blankline.nvim`
-- See `:help ibl`
main = 'ibl',
opts = {},
},
-- "gc"/"gcc" to comment lines; block mappings are intentionally disabled
{
'numToStr/Comment.nvim',
opts = {
mappings = {
basic = false,
extra = true,
},
},
config = function(_, opts)
require('Comment').setup(opts)
local ft = require('Comment.ft')
ft.set('sh', { '#%s', '#%s' })
ft.set('bash', { '#%s', '#%s' })
ft.set('zsh', { '#%s', '#%s' })
-- Keep linewise comment UX while removing blockwise warning paths.
vim.keymap.set('n', 'gc', '<Plug>(comment_toggle_linewise)', {
remap = true,
desc = 'Comment toggle linewise',
})
vim.keymap.set('x', 'gc', '<Plug>(comment_toggle_linewise_visual)', {
remap = true,
desc = 'Comment toggle linewise (visual)',
})
vim.keymap.set('n', 'gcc', function()
return vim.v.count == 0 and '<Plug>(comment_toggle_linewise_current)' or '<Plug>(comment_toggle_linewise_count)'
end, {
expr = true,
remap = true,
desc = 'Comment toggle current line',
})
end,
},
{
-- Highlight, edit, and navigate code
'nvim-treesitter/nvim-treesitter',
dependencies = {
'nvim-treesitter/nvim-treesitter-textobjects',
},
build = ':TSUpdate',
},
-- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart
-- These are some example plugins that I've included in the kickstart repository.
-- Uncomment any of the lines below to enable them.
-- require 'kickstart.plugins.autoformat',
-- require 'kickstart.plugins.debug',
-- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
-- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping
-- up-to-date with whatever is in the kickstart repo.
-- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going.
--
-- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins
{ import = 'custom.plugins' },
}, {})
-- [[ Setting options ]]
-- See `:help vim.o`
-- NOTE: You can change these options as you wish!
-- Highlight the current line
vim.o.cursorline = true
-- Highlight the current column
vim.o.cursorcolumn = true
-- Always show tabline for full file path display
vim.o.showtabline = 2
-- Highlight all search matches
vim.o.hlsearch = true
-- Make line numbers default
vim.wo.number = true
-- Enable mouse mode
vim.o.mouse = 'a'
-- Sync clipboard between OS and Neovim.
-- Remove this option if you want your OS clipboard to remain independent.
-- See `:help 'clipboard'`
vim.o.clipboard = 'unnamedplus'
-- Enable break indent, make long lines wrap with indentation
vim.o.breakindent = true
-- Save undo history
vim.o.undofile = true
-- Muchos level of undo
vim.o.undolevels = 500
-- Keep a long history of commands
vim.o.history = 5000
-- Limit syntax highlighting on very long lines
vim.o.synmaxcol = 5000
-- Start scrolling a few lines before the border (more context around the cursor)
vim.o.scrolloff = 4
-- Start horizontal scrolling a few columns before the border
vim.o.sidescrolloff = 4
-- Hide mode (e.g. '-- INSERT ----') in the command line because it's in the status line
vim.o.showmode = false
-- Disable the startup intro screen so plain `nvim` starts on a clean empty buffer
vim.opt.shortmess:append 'I'
-- Case-insensitive searching UNLESS \C or capital in search
vim.o.ignorecase = true
vim.o.smartcase = true
-- Wrapping is ugly, off by default
vim.o.wrap = false
-- But if you switch from nowrap to wrap, try not to wrap in the middle of words
vim.o.linebreak = true
-- Keep signcolumn on by default
vim.wo.signcolumn = 'yes'
-- Decrease update time
vim.o.updatetime = 250
vim.o.timeoutlen = 300
-- Set completeopt to have a better completion experience
vim.o.completeopt = 'menuone,noselect'
-- Show vertical lines at common line-length max values
vim.o.colorcolumn = '80,100,120'
-- [[ Basic Keymaps ]]
-- Keymaps for better default experience
-- See `:help vim.keymap.set()`
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })
-- Remap for dealing with word wrap
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
-- Diagnostic keymaps
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' })
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' })
vim.keymap.set('n', '<leader>E', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' })
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' })
-- Use ctrl-[hjkl] to change the active split
vim.api.nvim_set_keymap('n', '<C-k>', ':wincmd k<CR>', {silent = true})
vim.api.nvim_set_keymap('n', '<C-j>', ':wincmd j<CR>', {silent = true})
vim.api.nvim_set_keymap('n', '<C-h>', ':wincmd h<CR>', {silent = true})
vim.api.nvim_set_keymap('n', '<C-l>', ':wincmd l<CR>', {silent = true})
-- Return to NORMAL with jj
vim.keymap.set('i', 'jj', '<esc>')
-- Exit Terminal mode with Ctrl-Space (easy to press)
vim.keymap.set('t', '<C-Space>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
-- Set terminal scrollback buffer to 100,000 lines (for Claude Code and other terminals)
-- Safe on modern systems, uses ~100-200MB RAM at full capacity
vim.opt.scrollback = 100000
-- Set special characters for things like trailing spaces (trail) end-of-line (eol)
vim.opt.listchars:append({ trail = '·' })
vim.opt.listchars:append({ eol = '$' })
vim.opt.listchars:append({ extends = '→' })
-- Show or hide special characters
vim.keymap.set('n', '<localleader>ts', ':set list!<cr>', { desc = '[T]oggle [s]pecial characters' })
-- Oil.nvim (same key binding as neo-tree)
vim.keymap.set("n", "-", "<CMD>Oil<CR>", { desc = "Open parent directory" })
vim.keymap.set("n", "<leader>e", "<CMD>Oil<CR>", { desc = "Open file explorer (Oil)" })
-- Screenshot workflow
vim.keymap.set("n", "<leader>ss", "<CMD>Oil ~/screenshots<CR>", { desc = "Open screenshots directory" })
-- Command to insert the latest screenshot path
vim.api.nvim_create_user_command('LatestScreenshot', function()
local handle = io.popen("ls -t ~/screenshots/*.png 2>/dev/null | head -1")
local result = handle:read("*a")
handle:close()
local screenshot = result:gsub("\n", "")
if screenshot ~= "" then
vim.api.nvim_put({screenshot}, "", true, true)
else
vim.notify("No screenshots found", vim.log.levels.WARN)
end
end, { desc = "Insert path of latest screenshot" })
-- Command to copy latest screenshot path to clipboard
vim.api.nvim_create_user_command('CopyLatestScreenshot', function()
local handle = io.popen("ls -t ~/screenshots/*.png 2>/dev/null | head -1")
local result = handle:read("*a")
handle:close()
local screenshot = result:gsub("\n", "")
if screenshot ~= "" then
vim.fn.setreg("+", screenshot)
vim.notify("Copied: " .. screenshot)
else
vim.notify("No screenshots found", vim.log.levels.WARN)
end
end, { desc = "Copy latest screenshot path to clipboard" })
-- Add confirmation for window quit to prevent accidental closing
vim.keymap.set('n', '<C-w>q', function()
local choice = vim.fn.confirm("Close this window?", "&Yes\n&No", 2)
if choice == 1 then
vim.cmd('quit')
end
end, { desc = 'Quit window with confirmation' })
-- Also protect C-w C-q (holding Ctrl while pressing q)
vim.keymap.set('n', '<C-w><C-q>', function()
local choice = vim.fn.confirm("Close this window?", "&Yes\n&No", 2)
if choice == 1 then
vim.cmd('quit')
end
end, { desc = 'Quit window with confirmation' })
-- [[ Highlight on yank ]]
-- See `:help vim.highlight.on_yank()`
local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true })
vim.api.nvim_create_autocmd('TextYankPost', {
callback = function()
vim.highlight.on_yank()
end,
group = highlight_group,
pattern = '*',
})
-- [[ Set defaults for new empty buffers ]]
local empty_buffer_group = vim.api.nvim_create_augroup('EmptyBufferDefaults', { clear = true })
vim.api.nvim_create_autocmd('BufEnter', {
callback = function()
-- Check if this is a new empty buffer
local buf = vim.api.nvim_get_current_buf()
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
local is_empty = #lines == 1 and lines[1] == ''
local has_name = vim.api.nvim_buf_get_name(buf) ~= ''
-- Only apply to unnamed empty buffers
if is_empty and not has_name then
vim.bo.filetype = 'markdown'
vim.wo.wrap = true
vim.wo.spell = true
end
end,
group = empty_buffer_group,
pattern = '*',
})
-- [[ Set .mdx files as markdown ]]
vim.api.nvim_create_autocmd({'BufRead', 'BufNewFile'}, {
pattern = '*.mdx',
command = 'set filetype=markdown',
})
-- [[ Set large scrollback for terminal buffers ]]
vim.api.nvim_create_autocmd('TermOpen', {
callback = function()
-- 100k lines uses ~100-200MB RAM when full
vim.opt_local.scrollback = 100000
end,
desc = 'Set large scrollback buffer for terminals',
})
-- [[ Configure Snacks Picker ]]
local function project_root()
local bufname = vim.api.nvim_buf_get_name(0)
local start = bufname ~= '' and vim.fs.dirname(bufname) or vim.uv.cwd()
return vim.fs.root(start, { '.git', '.hg', '.svn' }) or vim.uv.cwd()
end
vim.keymap.set('n', '<leader>?', function() Snacks.picker.recent() end, { desc = '[?] Find recently opened files' })
vim.keymap.set('n', '<leader><space>', function() Snacks.picker.buffers() end, { desc = '[ ] Find existing buffers' })
vim.keymap.set('n', '<leader><leader>', function() require('snacks').dashboard() end, { desc = 'Dashboard' })
vim.keymap.set('n', '<leader>/', function() Snacks.picker.lines() end, { desc = '[/] Fuzzily search in current buffer' })
vim.keymap.set('n', '<leader>ff', function() Snacks.picker.files({ cwd = project_root() }) end, { desc = '[F]ind [F]iles' })
vim.keymap.set('n', '<leader>fp', function() Snacks.picker.projects() end, { desc = '[F]ind [P]rojects' })
vim.keymap.set('n', '<leader>gf', function() Snacks.picker.git_files({ cwd = project_root() }) end, { desc = 'Search [G]it [F]iles' })
vim.keymap.set('n', '<leader>sf', function() Snacks.picker.files({ cwd = project_root() }) end, { desc = '[S]earch [F]iles' })
vim.keymap.set('n', '<leader>sh', function() Snacks.picker.help() end, { desc = '[S]earch [H]elp' })
vim.keymap.set({ 'n', 'x' }, '<leader>sw', function() Snacks.picker.grep_word({ cwd = project_root() }) end, { desc = '[S]earch current [W]ord' })
vim.keymap.set('n', '<leader>sg', function() Snacks.picker.grep({ cwd = project_root() }) end, { desc = '[S]earch by [G]rep' })
vim.keymap.set('n', '<leader>sG', function() Snacks.picker.grep({ cwd = project_root() }) end, { desc = '[S]earch by [G]rep on project root' })
vim.keymap.set('n', '<leader>sd', function() Snacks.picker.diagnostics() end, { desc = '[S]earch [D]iagnostics' })
vim.keymap.set('n', '<leader>sr', function() Snacks.picker.resume() end, { desc = '[S]earch [R]esume' })
-- [[ Configure Treesitter ]]
-- See `:help nvim-treesitter`
-- Defer Treesitter setup after first render to improve startup time of 'nvim {filename}'
vim.defer_fn(function()
require('nvim-treesitter.configs').setup {
-- Add languages to be installed here that you want installed for treesitter
ensure_installed = {
-- Programming languages
'c', 'cpp', 'c_sharp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript',
'typescript', 'php', 'perl', 'zig', 'svelte',
-- Documentation and config
'vimdoc', 'vim', 'markdown', 'markdown_inline', 'latex', 'mermaid',
-- Shell and system
'bash', 'awk', 'powershell', 'tmux', 'ssh_config', 'passwd',
-- Git
'diff', 'git_rebase', 'gitcommit', 'gitignore', 'gitattributes', 'git_config',
-- Data formats
'json', 'jsonc', 'json5', 'yaml', 'toml', 'xml', 'csv', 'graphql', 'jq',
-- Web
'html', 'css', 'scss', 'http', 'nginx', 'caddy',
-- DevOps and cloud
'dockerfile', 'terraform', 'helm', 'bicep',
-- Build tools and package managers
'make', 'cmake', 'requirements', 'pymanifest', 'editorconfig',
-- Go ecosystem
'gomod', 'gosum', 'gowork', 'gotmpl', 'goctl',
-- Documentation
'jsdoc', 'luadoc', 'godot_resource',
-- Other
'sql', 'regex', 'printf', 'gpg'
},
-- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
auto_install = false,
highlight = { enable = true },
indent = { enable = true },
incremental_selection = {
enable = true,
keymaps = {
init_selection = '<c-space>',
node_incremental = '<c-space>',
scope_incremental = '<c-s>',
node_decremental = '<M-space>',
},
},
textobjects = {
select = {
enable = true,
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
keymaps = {
-- You can use the capture groups defined in textobjects.scm
['aa'] = '@parameter.outer',
['ia'] = '@parameter.inner',
['af'] = '@function.outer',
['if'] = '@function.inner',
['ac'] = '@class.outer',
['ic'] = '@class.inner',
},
},
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
[']m'] = '@function.outer',
[']]'] = '@class.outer',
},
goto_next_end = {
[']M'] = '@function.outer',
[']['] = '@class.outer',
},
goto_previous_start = {
['[m'] = '@function.outer',
['[['] = '@class.outer',
},
goto_previous_end = {
['[M'] = '@function.outer',
['[]'] = '@class.outer',
},
},
swap = {
enable = true,
swap_next = {
[']a'] = '@parameter.inner',
},
swap_previous = {
['[a'] = '@parameter.inner',
},
},
},
}
end, 0)
-- [[ Configure LSP ]]
-- This function gets run when an LSP connects to a particular buffer.
local on_attach = function(_, bufnr)
-- NOTE: Remember that lua is a real programming language, and as such it is possible
-- to define small helper and utility functions so you don't have to repeat yourself
-- many times.
--
-- In this case, we create a function that lets us more easily define mappings specific
-- for LSP related items. It sets the mode, buffer and description for us each time.
local nmap = function(keys, func, desc)
if desc then
desc = 'LSP: ' .. desc
end
vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
end
nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
nmap('gd', function() Snacks.picker.lsp_definitions() end, '[G]oto [D]efinition')
nmap('gr', function() Snacks.picker.lsp_references() end, '[G]oto [R]eferences')
nmap('gI', function() Snacks.picker.lsp_implementations() end, '[G]oto [I]mplementation')
nmap('<leader>D', function() Snacks.picker.lsp_type_definitions() end, 'Type [D]efinition')
nmap('<leader>ds', function() Snacks.picker.lsp_symbols() end, '[D]ocument [S]ymbols')
nmap('<leader>ws', function() Snacks.picker.lsp_workspace_symbols() end, '[W]orkspace [S]ymbols')
-- See `:help K` for why this keymap
nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
nmap('gK', vim.lsp.buf.signature_help, 'Signature Documentation')
-- Lesser used LSP functionality
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
nmap('<leader>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, '[W]orkspace [L]ist Folders')
-- Add format keymap
nmap('<leader>cf', vim.lsp.buf.format, '[C]ode [F]ormat')
-- Create a command `:Format` local to the LSP buffer
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
vim.lsp.buf.format()
end, { desc = 'Format current buffer with LSP' })
end
-- document existing key chains
require('which-key').add({
{ "<leader>c", group = "Code" },
{ "<leader>c_", hidden = true },
{ "<leader>d", group = "Document" },
{ "<leader>d_", hidden = true },
{ "<leader>f", group = "Find Files" },
{ "<leader>f_", hidden = true },
{ "<leader>g", group = "Git" },
{ "<leader>g_", hidden = true },
{ "<leader>r", group = "Rename" },
{ "<leader>r_", hidden = true },
{ "<leader>s", group = "Search" },
{ "<leader>s_", hidden = true },
{ "<leader>w", group = "Workspace" },
{ "<leader>w_", hidden = true },
{ "<leader>h", group = "Harpoon" },
{ "<leader>h_", hidden = true },
{ "<leader>b", group = "Buffer" },
{ "<leader>b_", hidden = true },
{ "<leader>n", group = "Notes/Snippets" },
{ "<leader>n_", hidden = true },
{ "<leader>t", group = "Theme" },
{ "<leader>t_", hidden = true },
{ "<leader>1", hidden = true }, -- Hide harpoon file 1
{ "<leader>2", hidden = true }, -- Hide harpoon file 2
{ "<leader>3", hidden = true }, -- Hide harpoon file 3
{ "<leader>4", hidden = true }, -- Hide harpoon file 4
{ "-", desc = "Oil - File Manager" },
{ "<leader>e", desc = "Oil File Explorer" },
{ "<leader>u", desc = "Toggle Gundo Tree" },
{ "<leader>o", desc = "Toggle Outline" },
{ "<leader>z", desc = "Zen Mode" },
{ "<leader>?", desc = "Recent Files" },
{ "<leader><space>", desc = "Open Buffers" },
{ "<leader>/", desc = "Search Current Buffer" }
})
require('mason').setup()
local mason_lspconfig = require 'mason-lspconfig'
-- 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.
--
-- If you want to override the default filetypes that your language server will attach to you can
-- define the property 'filetypes' to the map in question.
local servers = {
-- clangd = {},
-- gopls = {},
-- pyright = {},
-- rust_analyzer = {},
-- ts_ls = {},
-- html = { filetypes = { 'html', 'twig', 'hbs'} },
lua_ls = {
Lua = {
workspace = { checkThirdParty = false },
telemetry = { enable = false },
-- NOTE: toggle below to ignore Lua_LS's noisy `missing-fields` warnings
-- diagnostics = { disable = { 'missing-fields' } },
},
},
}
-- Setup basic LSP capabilities
local capabilities = vim.lsp.protocol.make_client_capabilities()
local blink_ok, blink = pcall(require, 'blink.cmp')
if blink_ok then
capabilities = blink.get_lsp_capabilities(capabilities)
end
mason_lspconfig.setup {
ensure_installed = vim.tbl_keys(servers),
}
vim.lsp.config('*', {
capabilities = capabilities,
on_attach = on_attach,
})
for server_name, server_settings in pairs(servers) do
vim.lsp.config(server_name, {
settings = server_settings,
filetypes = server_settings.filetypes,
})
end
vim.lsp.enable(vim.tbl_keys(servers))
-- Create a namespace for extmarks
local ns_id = vim.api.nvim_create_namespace('blingWordHighlights')
_G.blingWord = function(n)
-- Yank the current word into the z register and retrieve it
vim.cmd('normal! "zyiw')
local word = vim.fn.getreg('z')
-- Escape the word for use in a Lua pattern
local escaped_word = vim.pesc(word)
-- Function to apply highlighting in a buffer
local function applyHighlight(buf)
-- Clear existing extmarks in this namespace
vim.api.nvim_buf_clear_namespace(buf, ns_id, 0, -1)
-- Search for the word in the buffer and apply extmarks
local line_count = vim.api.nvim_buf_line_count(buf)
for line = 0, line_count - 1 do
local text = vim.api.nvim_buf_get_lines(buf, line, line + 1, false)[1]
for index in string.gmatch(text, '()' .. escaped_word .. '()') do
-- -1 because Lua indexing is 1-based and Neovim API expects 0-based indexing
vim.api.nvim_buf_set_extmark(buf, ns_id, line, index - 1, {
end_line = line,
end_col = index - 1 + #word,
hl_group = 'BlingWord' .. n
})
end
end
end
-- Iterate over all windows in the current tab
for _, win_id in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
local buf_id = vim.api.nvim_win_get_buf(win_id)
-- Check if the buffer is loaded to avoid processing unloaded buffers
if vim.api.nvim_buf_is_loaded(buf_id) then
applyHighlight(buf_id)
end
end
end
-- Key mappings
vim.api.nvim_set_keymap('n', '<localleader>h0', ':lua vim.fn.clearmatches()<CR>:noh<CR>', { noremap = true, silent = true })
for i = 1, 6 do
vim.api.nvim_set_keymap('n', '<localleader>h' .. i, ':lua blingWord(' .. i .. ')<CR>', { noremap = true, silent = true })
end
-- Safety toggle for TreeSitter highlighting if issues occur
vim.keymap.set('n', '<localleader>th', ':TSBufToggle highlight<CR>', { desc = 'Toggle TS highlight for this buffer' })
-- Highlight definitions
local colors = {
'#6eff81', -- Neon Lime Green
'#ff75ba', -- Hot Pink
'#70f8ff', -- Electric Blue
'#ffff73', -- Bright Yellow
'#f7554f', -- Vivid Orange
'#cf65fc' -- Radiant Purple
}
for i, color in ipairs(colors) do
vim.api.nvim_command('highlight def BlingWord' .. i .. ' guifg=#000000 ctermfg=16 guibg=' .. color .. ' ctermbg=' .. i + 213)
end
-- The line beneath this is called `modeline`. See `:help modeline`
-- vim: ts=2 sts=2 sw=2 et