-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinit.lua
More file actions
1318 lines (1194 loc) · 45.5 KB
/
init.lua
File metadata and controls
1318 lines (1194 loc) · 45.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
-- Neovim configuration with Zig, Rust, Go, and Python LSP support
-- Bootstrap lazy.nvim plugin manager
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",
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
-- Basic settings
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.expandtab = true
vim.opt.shiftwidth = 4
vim.opt.tabstop = 4
vim.opt.smartindent = true
vim.opt.wrap = false
vim.opt.swapfile = false
vim.opt.backup = false
vim.opt.hlsearch = false
vim.opt.incsearch = true
vim.opt.termguicolors = true
vim.opt.scrolloff = 8
vim.opt.signcolumn = "yes"
vim.opt.updatetime = 50
vim.opt.colorcolumn = "100"
-- Clipboard configuration (macOS uses pbcopy/pbpaste by default)
-- Uncomment below for Wayland/Crostini if needed
-- vim.g.clipboard = {
-- name = 'WaylandClipboard',
-- copy = {
-- ['+'] = 'wl-copy',
-- ['*'] = 'wl-copy',
-- },
-- paste = {
-- ['+'] = 'wl-paste --no-newline',
-- ['*'] = 'wl-paste --no-newline',
-- },
-- cache_enabled = 0,
-- }
-- Set leader key
vim.g.mapleader = " "
vim.g.maplocalleader = " "
-- Plugin setup
require("lazy").setup({
-- Which-key: shows available keymaps as you type
{
"folke/which-key.nvim",
event = "VeryLazy",
config = function()
local wk = require("which-key")
wk.setup({
preset = "helix",
delay = 200, -- Show quickly
icons = { mappings = false },
win = {
border = "rounded",
padding = { 1, 2 },
title = true,
title_pos = "center",
},
-- Show pressed keys in cmdline
show_keys = true,
-- Don't hide immediately after key press
triggers = {
{ "<auto>", mode = "nxso" },
},
})
-- Learning mode: show which-key and echo pressed keys
local learning_mode = false
vim.api.nvim_create_user_command("LearnKeys", function()
learning_mode = not learning_mode
if learning_mode then
vim.o.showcmd = true
vim.o.showcmdloc = "statusline"
wk.setup({ delay = 0 }) -- Show immediately
vim.notify("Learning mode ON - which-key shows immediately", vim.log.levels.INFO)
else
wk.setup({ delay = 200 })
vim.notify("Learning mode OFF", vim.log.levels.INFO)
end
end, { desc = "Toggle key learning mode" })
vim.keymap.set("n", "<leader>L", "<cmd>LearnKeys<cr>", { desc = "Help: Toggle learning mode" })
-- Show which-key popup in visual mode
vim.keymap.set("v", "<leader>", function()
wk.show({ mode = "v", keys = "<leader>" })
end, { desc = "Show visual mode keymaps" })
-- Toggle which-key popup manually (works in any mode)
vim.keymap.set({ "n", "v" }, "<C-/>", function()
local mode = vim.fn.mode()
if mode == "v" or mode == "V" or mode == "\22" then -- visual modes
wk.show({ mode = "v", keys = "" })
else
wk.show({ mode = "n", keys = "" })
end
end, { desc = "Help: Show all keymaps" })
-- Contextual keymap helper (mode & filetype aware)
local helper_win = nil
local helper_buf = nil
local helper_active = false
local function close_helper()
if helper_win and vim.api.nvim_win_is_valid(helper_win) then
vim.api.nvim_win_close(helper_win, true)
end
helper_win = nil
helper_buf = nil
helper_active = false
end
local function update_helper()
if not helper_active then return end
local mode = vim.fn.mode()
local ft = vim.bo.filetype
local mode_name = ({ n = "NORMAL", v = "VISUAL", V = "V-LINE", ["\22"] = "V-BLOCK", i = "INSERT" })[mode] or mode:upper()
-- Determine which keymaps to show based on mode
local keymap_mode = "n"
if mode == "v" or mode == "V" or mode == "\22" then
keymap_mode = "v"
end
-- Filetype to category mapping
local ft_categories = {
python = { "Python" },
go = { "Go" },
rust = { "Rust" },
zig = { "Zig" },
markdown = { "Markdown", "Media", "Writing" },
}
local relevant_cats = ft_categories[ft] or {}
-- Collect keymaps
local lines = {
"┌─ " .. mode_name .. " │ " .. (ft ~= "" and ft or "no ft") .. " ─┐",
"",
}
local categories = {}
-- Global keymaps
for _, m in ipairs(vim.api.nvim_get_keymap(keymap_mode)) do
if m.desc and m.lhs:match("^ ") then
local cat = m.desc:match("^([^:]+):") or "Other"
categories[cat] = categories[cat] or {}
local key = m.lhs:gsub(" ", "␣")
table.insert(categories[cat], key .. " → " .. m.desc:gsub("^[^:]+: ", ""))
end
end
-- Buffer-local keymaps
for _, m in ipairs(vim.api.nvim_buf_get_keymap(0, keymap_mode)) do
if m.desc and m.lhs:match("^ ") then
local cat = m.desc:match("^([^:]+):") or "Buffer"
categories[cat] = categories[cat] or {}
local key = m.lhs:gsub(" ", "␣")
table.insert(categories[cat], key .. " → " .. m.desc:gsub("^[^:]+: ", "") .. " ⋆")
end
end
-- Show relevant categories first, then others
local shown = {}
for _, cat in ipairs(relevant_cats) do
if categories[cat] then
table.insert(lines, "▸ " .. cat)
for _, m in ipairs(categories[cat]) do
table.insert(lines, " " .. m)
end
table.insert(lines, "")
shown[cat] = true
end
end
-- Show other categories
for cat, maps in pairs(categories) do
if not shown[cat] then
table.insert(lines, "▸ " .. cat)
for _, m in ipairs(maps) do
table.insert(lines, " " .. m)
end
table.insert(lines, "")
end
end
table.insert(lines, "")
table.insert(lines, "␣K to close │ ⋆ = buffer-local")
-- Update or create buffer
if not helper_buf or not vim.api.nvim_buf_is_valid(helper_buf) then
helper_buf = vim.api.nvim_create_buf(false, true)
end
vim.api.nvim_buf_set_option(helper_buf, "modifiable", true)
vim.api.nvim_buf_set_lines(helper_buf, 0, -1, false, lines)
vim.api.nvim_buf_set_option(helper_buf, "modifiable", false)
-- Create or update window
local width = 42
local height = math.min(#lines, vim.o.lines - 4)
if not helper_win or not vim.api.nvim_win_is_valid(helper_win) then
helper_win = vim.api.nvim_open_win(helper_buf, false, {
relative = "editor",
row = 1,
col = vim.o.columns - width - 2,
width = width,
height = height,
style = "minimal",
border = "rounded",
title = " Keys ",
title_pos = "center",
})
vim.api.nvim_win_set_option(helper_win, "winblend", 15)
vim.api.nvim_win_set_option(helper_win, "winhighlight", "Normal:NormalFloat")
else
vim.api.nvim_win_set_config(helper_win, { height = height })
end
end
local function toggle_helper()
if helper_active then
close_helper()
else
helper_active = true
update_helper()
-- Auto-update on mode/buffer change
local group = vim.api.nvim_create_augroup("KeymapHelper", { clear = true })
vim.api.nvim_create_autocmd({ "ModeChanged", "BufEnter", "FileType" }, {
group = group,
callback = function()
vim.defer_fn(update_helper, 50)
end,
})
end
end
vim.api.nvim_create_user_command("KeymapHelper", toggle_helper, { desc = "Toggle contextual keymap helper" })
vim.keymap.set({ "n", "v" }, "<leader>K", toggle_helper, { desc = "Help: Toggle keymap helper" })
-- Auto-generate group names from "Category: action" description pattern
-- This runs after all plugins load, so it sees all keymaps
vim.api.nvim_create_autocmd("User", {
pattern = "VeryLazy",
callback = function()
local groups = {}
for _, map in ipairs(vim.api.nvim_get_keymap("n")) do
if map.desc and map.lhs:match("^ ") then -- leader maps start with space
local prefix = map.lhs:sub(1, 2) -- e.g. " p" for <leader>p
if not groups[prefix] and #map.lhs > 2 then
-- Extract group name from "Category: action" pattern
local group_name = map.desc:match("^([^:]+):")
if group_name then
groups[prefix] = group_name
end
end
end
end
-- Register groups with which-key
local spec = {}
for prefix, name in pairs(groups) do
table.insert(spec, { "<leader>" .. prefix:sub(2), group = name })
end
if #spec > 0 then
wk.add(spec)
end
end,
})
-- Show all keymaps with Telescope
vim.keymap.set("n", "<leader>?", "<cmd>Telescope keymaps<cr>", { desc = "Help: Search keymaps" })
-- AI-powered vim tutor
vim.api.nvim_create_user_command("Tutor", function()
-- Gather all keymaps with descriptions
local lines = {
"# Neovim Keymaps Reference",
"",
"Ask me anything about these keymaps or how to do something in Neovim!",
"",
"## Leader Keymaps (<Space> is leader)",
"",
}
-- Collect and sort keymaps by category
local categories = {}
for _, map in ipairs(vim.api.nvim_get_keymap("n")) do
if map.desc and map.lhs:match("^ ") then
local cat = map.desc:match("^([^:]+):") or "Other"
categories[cat] = categories[cat] or {}
local key = map.lhs:gsub(" ", "<leader>")
table.insert(categories[cat], "- `" .. key .. "` — " .. map.desc)
end
end
-- Add visual mode keymaps
for _, map in ipairs(vim.api.nvim_get_keymap("v")) do
if map.desc and map.lhs:match("^ ") then
local cat = map.desc:match("^([^:]+):") or "Other"
categories[cat] = categories[cat] or {}
local key = map.lhs:gsub(" ", "<leader>")
table.insert(categories[cat], "- `" .. key .. "` (visual) — " .. map.desc)
end
end
-- Format by category
for cat, maps in pairs(categories) do
table.insert(lines, "### " .. cat)
for _, m in ipairs(maps) do
table.insert(lines, m)
end
table.insert(lines, "")
end
-- Add comprehensive vim movements
table.insert(lines, "## Movements")
table.insert(lines, "")
table.insert(lines, "### Basic Motion")
table.insert(lines, "- `h/j/k/l` — left/down/up/right")
table.insert(lines, "- `w/W` — word/WORD forward")
table.insert(lines, "- `b/B` — word/WORD backward")
table.insert(lines, "- `e/E` — end of word/WORD")
table.insert(lines, "- `0/$` — start/end of line")
table.insert(lines, "- `^` — first non-blank char")
table.insert(lines, "")
table.insert(lines, "### Find on Line")
table.insert(lines, "- `f{char}` — find char forward")
table.insert(lines, "- `F{char}` — find char backward")
table.insert(lines, "- `t{char}` — till char forward")
table.insert(lines, "- `T{char}` — till char backward")
table.insert(lines, "- `;/,` — repeat find forward/backward")
table.insert(lines, "")
table.insert(lines, "### Jumping")
table.insert(lines, "- `gg/G` — top/bottom of file")
table.insert(lines, "- `{num}G` — go to line number")
table.insert(lines, "- `{/}` — paragraph up/down")
table.insert(lines, "- `%` — matching bracket")
table.insert(lines, "- `<C-o>/<C-i>` — jump list back/forward")
table.insert(lines, "- `<C-d>/<C-u>` — half page down/up")
table.insert(lines, "- `zz/zt/zb` — center/top/bottom cursor")
table.insert(lines, "")
table.insert(lines, "### Search")
table.insert(lines, "- `/{pattern}` — search forward")
table.insert(lines, "- `?{pattern}` — search backward")
table.insert(lines, "- `n/N` — next/previous match")
table.insert(lines, "- `*/#` — search word under cursor")
table.insert(lines, "- `gd` — go to definition (LSP)")
table.insert(lines, "")
table.insert(lines, "## Text Objects")
table.insert(lines, "")
table.insert(lines, "Use with operators: `d`(delete), `c`(change), `y`(yank), `v`(visual)")
table.insert(lines, "")
table.insert(lines, "### Inner (i) vs Around (a)")
table.insert(lines, "- `iw/aw` — inner/around word")
table.insert(lines, "- `is/as` — inner/around sentence")
table.insert(lines, "- `ip/ap` — inner/around paragraph")
table.insert(lines, "")
table.insert(lines, "### Delimiters")
table.insert(lines, "- `i\"/a\"` — inside/around double quotes")
table.insert(lines, "- `i'/a'` — inside/around single quotes")
table.insert(lines, "- `i)/a)` or `ib/ab` — inside/around parens")
table.insert(lines, "- `i]/a]` — inside/around brackets")
table.insert(lines, "- `i}/a}` or `iB/aB` — inside/around braces")
table.insert(lines, "- `i>/a>` — inside/around angle brackets")
table.insert(lines, "- `it/at` — inside/around HTML tags")
table.insert(lines, "")
table.insert(lines, "## Efficient Editing Patterns")
table.insert(lines, "")
table.insert(lines, "### Common Combos")
table.insert(lines, "- `ciw` — change word under cursor")
table.insert(lines, "- `ci\"` — change inside quotes")
table.insert(lines, "- `ca)` — change around parentheses")
table.insert(lines, "- `dap` — delete paragraph")
table.insert(lines, "- `yiw` — yank word")
table.insert(lines, "- `vi{` — select inside braces")
table.insert(lines, "")
table.insert(lines, "### Repeat & Undo")
table.insert(lines, "- `.` — repeat last change")
table.insert(lines, "- `u/<C-r>` — undo/redo")
table.insert(lines, "- `@:` — repeat last command")
table.insert(lines, "")
table.insert(lines, "### Registers")
table.insert(lines, "- `\"ay` — yank to register a")
table.insert(lines, "- `\"ap` — paste from register a")
table.insert(lines, "- `\"+y` — yank to system clipboard")
table.insert(lines, "- `\"+p` — paste from system clipboard")
table.insert(lines, "- `:reg` — show all registers")
table.insert(lines, "")
table.insert(lines, "### Macros")
table.insert(lines, "- `qa` — start recording macro to register a")
table.insert(lines, "- `q` — stop recording")
table.insert(lines, "- `@a` — play macro from register a")
table.insert(lines, "- `@@` — repeat last macro")
table.insert(lines, "")
-- Create buffer with content
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
vim.api.nvim_buf_set_option(buf, "filetype", "markdown")
vim.api.nvim_buf_set_option(buf, "buftype", "nofile")
vim.api.nvim_buf_set_name(buf, "[Tutor]")
-- Open tutor in a vertical split
vim.cmd("vsplit")
vim.api.nvim_win_set_buf(0, buf)
vim.cmd("wincmd H") -- Move to far left
vim.cmd("vertical resize 60")
vim.notify("Tutor opened. Press <leader>ac to open Claude and ask questions!", vim.log.levels.INFO)
end, { desc = "Open AI-powered Neovim tutor" })
vim.keymap.set("n", "<leader>h", "<cmd>Tutor<cr>", { desc = "Help: AI Tutor" })
end,
},
-- LSP Configuration
{
"neovim/nvim-lspconfig",
dependencies = {
-- Mason for managing LSP servers (optional)
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
-- Useful status updates for LSP
{ "j-hui/fidget.nvim", opts = {} },
-- Additional lua configuration for neovim
{ "folke/neodev.nvim", opts = {} },
},
config = function()
-- Setup Mason
require("mason").setup()
require("mason-lspconfig").setup({
ensure_installed = { "rust_analyzer", "gopls" },
automatic_installation = {
exclude = { "basedpyright" }, -- installed via uv instead
},
})
-- Setup LSP servers using the modern vim.lsp.config API
-- Rust analyzer (uses rust-analyzer from PATH or Mason)
vim.lsp.config['rust_analyzer'] = {
cmd = { "rust-analyzer" },
filetypes = { "rust" },
root_markers = { "Cargo.toml", ".git" },
}
-- Go language server (uses gopls from PATH or Mason)
vim.lsp.config.gopls = {
cmd = { "gopls" },
filetypes = { "go", "gomod", "gowork", "gotmpl" },
root_markers = { "go.mod", ".git", "go.work" },
}
-- Python language server (basedpyright - enhanced pyright fork)
vim.lsp.config.basedpyright = {
cmd = { "basedpyright-langserver", "--stdio" },
filetypes = { "python" },
root_markers = { "pyproject.toml", "setup.py", "setup.cfg", "requirements.txt", "uv.lock", ".git" },
settings = {
basedpyright = {
analysis = {
typeCheckingMode = "standard",
autoSearchPaths = true,
useLibraryCodeForTypes = true,
diagnosticMode = "openFilesOnly",
},
},
},
}
-- LSP keymaps
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
local opts = { buffer = ev.buf }
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
vim.keymap.set("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set("n", "<leader>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set("n", "<leader>D", vim.lsp.buf.type_definition, opts)
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
vim.keymap.set("n", "<leader>f", function()
vim.lsp.buf.format({ async = true })
end, opts)
end,
})
-- Setup ZLS (Zig Language Server)
vim.lsp.config.zls = {
cmd = { "zls" },
filetypes = { "zig", "zir" },
root_markers = { "zls.json", ".git", "build.zig" },
}
-- Enable all configured LSP servers
vim.lsp.enable("zls")
vim.lsp.enable("rust_analyzer")
vim.lsp.enable("gopls")
vim.lsp.enable("basedpyright")
end,
},
-- Autocompletion
{
"hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
},
config = function()
local cmp = require("cmp")
local luasnip = require("luasnip")
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}),
sources = {
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "path" },
},
})
end,
},
-- Treesitter for better syntax highlighting
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
main = "nvim-treesitter",
opts = {
ensure_installed = { "zig", "rust", "go", "lua", "vim", "vimdoc", "markdown", "markdown_inline", "python" },
auto_install = true,
highlight = { enable = true },
indent = { enable = true },
},
},
-- File explorer
{
"nvim-tree/nvim-tree.lua",
dependencies = { "nvim-tree/nvim-web-devicons" },
config = function()
require("nvim-tree").setup()
vim.keymap.set("n", "<leader>e", ":NvimTreeToggle<CR>", { silent = true })
end,
},
-- Fuzzy finder
{
"nvim-telescope/telescope.nvim",
branch = "master",
dependencies = { "nvim-lua/plenary.nvim" },
config = function()
local builtin = require("telescope.builtin")
vim.keymap.set("n", "<leader>ff", builtin.find_files, {})
vim.keymap.set("n", "<leader>fg", builtin.live_grep, {})
vim.keymap.set("n", "<leader>fb", builtin.buffers, {})
vim.keymap.set("n", "<leader>fh", builtin.help_tags, {})
end,
},
-- Color scheme
{
"folke/tokyonight.nvim",
lazy = false,
priority = 1000,
config = function()
vim.cmd([[colorscheme tokyonight-night]])
end,
},
-- Status line
{
"nvim-lualine/lualine.nvim",
dependencies = { "nvim-tree/nvim-web-devicons" },
config = function()
require("lualine").setup({
options = {
theme = "tokyonight",
},
})
end,
},
-- Git signs
{
"lewis6991/gitsigns.nvim",
config = function()
require("gitsigns").setup()
end,
},
-- Comment toggling
{
"numToStr/Comment.nvim",
config = function()
require("Comment").setup()
end,
},
-- Zen mode for distraction-free writing
{
"folke/zen-mode.nvim",
opts = {},
keys = {
{ "<leader>z", "<cmd>ZenMode<cr>", desc = "Writing: Zen Mode" },
},
},
-- Dim inactive text while writing
{
"folke/twilight.nvim",
opts = {},
},
-- Markdown rendering in-buffer
{
"MeanderingProgrammer/render-markdown.nvim",
dependencies = { "nvim-treesitter/nvim-treesitter", "nvim-tree/nvim-web-devicons" },
ft = { "markdown" },
opts = {},
keys = {
{ "<leader>mr", "<cmd>RenderMarkdown toggle<cr>", desc = "Markdown: Toggle rendering" },
},
},
-- Code outline/navigation (works with LSP + Treesitter)
{
"stevearc/aerial.nvim",
dependencies = { "nvim-treesitter/nvim-treesitter", "nvim-tree/nvim-web-devicons" },
opts = {
backends = { "treesitter", "lsp", "markdown", "man" },
layout = {
min_width = 30,
default_direction = "right",
},
filter_kind = false, -- show all symbol types
},
keys = {
{ "<leader>o", "<cmd>AerialToggle<cr>", desc = "Outline: Toggle" },
{ "<leader>O", "<cmd>AerialNavToggle<cr>", desc = "Outline: Toggle nav" },
{ "{", "<cmd>AerialPrev<cr>", desc = "Outline: Previous symbol" },
{ "}", "<cmd>AerialNext<cr>", desc = "Outline: Next symbol" },
},
},
-- Multi-cursor support (VSCode-style)
{
"mg979/vim-visual-multi",
branch = "master",
},
-- Snacks.nvim (required for claudecode.nvim terminal)
{
"folke/snacks.nvim",
priority = 1000,
lazy = false,
opts = {},
},
-- Claude Code AI integration
{
"coder/claudecode.nvim",
dependencies = { "folke/snacks.nvim" },
event = "VeryLazy", -- Load early but not blocking
config = function()
require("claudecode").setup({
terminal_cmd = vim.fn.expand("~/.claude/local/claude"),
})
-- Keymaps
vim.keymap.set("n", "<leader>ac", "<cmd>ClaudeCode<cr>", { desc = "AI: Toggle Claude" })
vim.keymap.set("n", "<leader>af", "<cmd>ClaudeCodeFocus<cr>", { desc = "AI: Focus Claude" })
vim.keymap.set("v", "<leader>as", "<cmd>ClaudeCodeSend<cr>", { desc = "AI: Send to Claude" })
vim.keymap.set("n", "<leader>ab", "<cmd>ClaudeCodeAdd %<cr>", { desc = "AI: Add buffer" })
vim.keymap.set("n", "<leader>aa", "<cmd>ClaudeCodeDiffAccept<cr>", { desc = "AI: Accept diff" })
vim.keymap.set("n", "<leader>ad", "<cmd>ClaudeCodeDiffDeny<cr>", { desc = "AI: Reject diff" })
-- Status check command
vim.api.nvim_create_user_command("ClaudeStatus", function()
local ok, claude = pcall(require, "claudecode")
if ok and claude.status then
vim.notify("Claude: " .. (claude.status() or "unknown"), vim.log.levels.INFO)
else
vim.notify("Claude: plugin loaded, checking connection...", vim.log.levels.INFO)
end
end, { desc = "Check Claude connection status" })
end,
},
-- Simple IPython terminal toggle (just works, no setup needed)
{
"akinsho/toggleterm.nvim",
version = "*",
config = function()
require("toggleterm").setup({
size = function(term)
if term.direction == "horizontal" then
return 15
elseif term.direction == "vertical" then
return vim.o.columns * 0.4
end
end,
open_mapping = [[<c-\>]],
direction = "vertical",
})
-- Dedicated IPython terminal
local Terminal = require("toggleterm.terminal").Terminal
local ipython = Terminal:new({
cmd = "ipython",
direction = "vertical",
hidden = true,
on_open = function(term)
vim.cmd("startinsert!")
end,
})
-- Toggle IPython REPL
vim.keymap.set("n", "<leader>pi", function() ipython:toggle() end, { desc = "Python: Toggle IPython" })
-- Send current line to IPython
vim.keymap.set("n", "<leader>pl", function()
local line = vim.api.nvim_get_current_line()
ipython:send(line, true)
end, { desc = "Python: Send line" })
-- Send visual selection to IPython
vim.keymap.set("v", "<leader>ps", function()
-- Get visual selection
local start_pos = vim.fn.getpos("'<")
local end_pos = vim.fn.getpos("'>")
local lines = vim.api.nvim_buf_get_lines(0, start_pos[2] - 1, end_pos[2], false)
if #lines > 0 then
-- Adjust first and last line for visual selection
lines[#lines] = string.sub(lines[#lines], 1, end_pos[3])
lines[1] = string.sub(lines[1], start_pos[3])
end
ipython:send(lines, true)
end, { desc = "Python: Send selection" })
-- Send paragraph to IPython
vim.keymap.set("n", "<leader>pp", function()
local start_line = vim.fn.search("^\\s*$", "bnW") + 1
local end_line = vim.fn.search("^\\s*$", "nW") - 1
if end_line < start_line then
end_line = vim.fn.line("$")
end
local lines = vim.api.nvim_buf_get_lines(0, start_line - 1, end_line, false)
ipython:send(lines, true)
end, { desc = "Python: Send paragraph" })
-- Send code block (# %% cell) to IPython
vim.keymap.set("n", "<leader>pb", function()
local current_line = vim.fn.line(".")
local start_line = vim.fn.search("^# %%", "bnW")
if start_line == 0 then start_line = 1 else start_line = start_line + 1 end
local end_line = vim.fn.search("^# %%", "nW") - 1
if end_line < start_line then end_line = vim.fn.line("$") end
local lines = vim.api.nvim_buf_get_lines(0, start_line - 1, end_line, false)
ipython:send(lines, true)
end, { desc = "Python: Send code block" })
-- Send block and move to next
vim.keymap.set("n", "<leader>pn", function()
vim.cmd("normal \\<leader>pb")
vim.fn.search("^# %%", "W")
end, { desc = "Python: Send block & next" })
-- Write selected lines from terminal to new Python buffer
vim.keymap.set("v", "<leader>pw", function()
-- Yank selection
vim.cmd('normal! "zy')
local content = vim.fn.getreg("z")
-- Clean up IPython prompts (In [1]:, Out[1]:, ...:, etc.)
local lines = {}
for line in content:gmatch("[^\n]+") do
-- Remove IPython input prompts
line = line:gsub("^In %[%d+%]: ", "")
-- Remove continuation prompts
line = line:gsub("^ %.%.%.: ", "")
-- Skip output prompts and their content
if not line:match("^Out%[%d+%]:") then
table.insert(lines, line)
end
end
-- Create new buffer with content
vim.cmd("enew")
vim.bo.filetype = "python"
vim.api.nvim_buf_set_lines(0, 0, -1, false, lines)
end, { desc = "Python: Write to new buffer" })
end,
},
-- Image rendering in terminal (for markdown images)
{
"3rd/image.nvim",
opts = {
backend = "kitty", -- or "ueberzug" for X11, "iterm" for iTerm2
max_width = 100,
max_height = 20,
max_height_window_percentage = 50,
integrations = {
markdown = {
enabled = true,
clear_in_insert_mode = true,
only_render_image_at_cursor = false,
},
},
},
},
-- Jupyter notebook editing (converts .ipynb to Python with cell markers)
{
"GCBallesteros/jupytext.nvim",
config = function()
require("jupytext").setup({
style = "percent", -- Use # %% cell markers
output_extension = "auto",
force_ft = nil,
})
end,
},
})
-- Additional keybindings
vim.keymap.set("n", "<leader>pv", vim.cmd.Ex)
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv")
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv")
vim.keymap.set("n", "J", "mzJ`z")
vim.keymap.set("n", "<C-d>", "<C-d>zz")
vim.keymap.set("n", "<C-u>", "<C-u>zz")
vim.keymap.set("n", "n", "nzzzv")
vim.keymap.set("n", "N", "Nzzzv")
vim.keymap.set("x", "<leader>p", [["_dP]])
vim.keymap.set({"n", "v"}, "<leader>y", [["+y]])
vim.keymap.set("n", "<leader>Y", [["+Y]])
vim.keymap.set({"n", "v"}, "<leader>d", [["_d]])
vim.keymap.set("n", "Q", "<nop>")
-- Disable Ctrl-Z in ClaudeCode terminal (prevents accidental suspend)
vim.api.nvim_create_autocmd("TermOpen", {
callback = function()
-- Check buffer name or terminal command for claude
local bufname = vim.api.nvim_buf_get_name(0):lower()
if bufname:match("claude") or bufname:match("ClaudeCode") then
vim.keymap.set("t", "<C-z>", "<nop>", { buffer = 0 })
end
-- Also set after a short delay to catch dynamically named terminals
vim.defer_fn(function()
local name = vim.api.nvim_buf_get_name(0):lower()
if name:match("claude") then
vim.keymap.set("t", "<C-z>", "<nop>", { buffer = 0 })
end
end, 100)
end,
})
-- Diagnostic configuration
vim.diagnostic.config({
virtual_text = true,
signs = true,
update_in_insert = false,
underline = true,
severity_sort = true,
float = {
border = "rounded",
source = "always",
header = "",
prefix = "",
},
})
-- Diagnostic keymaps
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
vim.keymap.set("n", "<leader>dl", vim.diagnostic.setloclist)
vim.keymap.set("n", "<leader>q", vim.diagnostic.setloclist)
-- Zig configuration
vim.api.nvim_create_autocmd("FileType", {
pattern = "zig",
callback = function()
-- Set makeprg to use zig build
vim.opt_local.makeprg = "zig build"
-- Set errorformat for Zig compiler errors
vim.opt_local.errorformat = "%f:%l:%c: %t%*[^:]: %m"
end,
})
-- Rust configuration
vim.api.nvim_create_autocmd("FileType", {
pattern = "rust",
callback = function()
-- Set makeprg to use cargo
vim.opt_local.makeprg = "cargo build"
-- Set errorformat for rustc compiler errors
vim.opt_local.errorformat =
"%E--> %f:%l:%c," ..
"%W--> %f:%l:%c," ..
"%C%m"
end,
})
-- Go configuration
vim.api.nvim_create_autocmd("FileType", {
pattern = "go",
callback = function()
-- Set makeprg to use go build
vim.opt_local.makeprg = "go build"
-- Set errorformat for Go compiler errors
vim.opt_local.errorformat = "%f:%l:%c: %m,%f:%l: %m"
end,
})
-- Python configuration
vim.api.nvim_create_autocmd("FileType", {
pattern = "python",
callback = function()
-- Use uv run for Python execution
vim.opt_local.makeprg = "uv run python %"
-- Python error format
vim.opt_local.errorformat = '%C %.%#,%A File "%f"\\, line %l%.%#,%Z%[%^ ]%\\@=%m'
end,
})
-- Markdown/prose configuration
vim.api.nvim_create_autocmd("FileType", {
pattern = "markdown",
callback = function()
vim.opt_local.wrap = true
vim.opt_local.linebreak = true
vim.opt_local.spell = true