-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
858 lines (764 loc) · 27.3 KB
/
init.lua
File metadata and controls
858 lines (764 loc) · 27.3 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
local vimrc = vim.fn.stdpath("config") .. "/vimrc.vim"
vim.cmd.source(vimrc)
vim.opt.mouse = ""
vim.opt.wrap = false
vim.opt.number = true
vim.opt.laststatus = 3
vim.opt.inccommand = "split"
vim.opt.termguicolors = true
vim.opt.relativenumber = true
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or 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)
local opts = {}
require("lazy").setup("plugins", opts)
local const = require("constants")
local builtin = require("telescope.builtin")
package.path = package.path .. ";" .. vim.fn.expand("$HOME") .. "/.luarocks/share/lua/5.1/?/init.lua"
package.path = package.path .. ";" .. vim.fn.expand("$HOME") .. "/.luarocks/share/lua/5.1/?.lua"
package.path = package.path .. ";" .. vim.fn.stdpath("config") .. "/temp.lua"
require("telescope").load_extension("lazygit")
-- local positive_look_behind = function(opts_1)
-- local cmd = ".,+22s/\\(" .. tostring(vim.fn.getreg("0")) .. "\\)\\@<=.*/" .. opts_1.args .. "/"
-- print(cmd)
-- vim.api.nvim_command(cmd)
-- return 0
-- end
--
-- vim.api.nvim_create_user_command("Pchange", positive_look_behind, { nargs = "?" })
-- vim.keymap.set("n", "<leader>lb", positive_look_behind)
local last_status = function()
local cmd
if const.last_status_flag == 3 then
cmd = "set laststatus=" .. const.last_status_flag
const.last_status_flag = 2
elseif const.last_status_flag == 2 then
cmd = "set laststatus=" .. const.last_status_flag
const.last_status_flag = 3
end
vim.api.nvim_command(cmd)
end
vim.keymap.set("n", "<leader>sl", last_status, {})
local shift_theme = function(opts_theme)
if opts_theme.args == "sol" then
vim.cmd.colorscheme("solarized-osaka")
elseif opts_theme.args == "cat" then
vim.cmd.colorscheme("catppuccin")
elseif opts_theme.args == "Toggle" then
if const.TshiftToggleConst == "1" then
const.TshiftToggleConst = "2"
vim.api.nvim_command("colorscheme catppuccin")
elseif const.TshiftToggleConst == "2" then
const.TshiftToggleConst = "3"
vim.api.nvim_command("colorscheme solarized-osaka")
elseif const.TshiftToggleConst == "3" then
const.TshiftToggleConst = "1"
vim.api.nvim_command("colorscheme tokyonight-night")
end
end
end
vim.api.nvim_create_user_command("Tshift", shift_theme, { nargs = "?" })
vim.keymap.set("n", "<leader>cs", ":Tshift Toggle<CR>", {})
-- local harpoon = require("telescope").load_extension("harpoon")
---------------------------- keymap for search escape ----------------------------
vim.keymap.set("n", "<Esc>", "<cmd>nohlsearch<CR>")
----------------------------------------------------------------------------------
--------------------------- keymap for diagnostics jump --------------------------
vim.keymap.set("n", "]d", ":lua vim.diagnostic.goto_next()<CR>", {})
vim.keymap.set("n", "[d", ":lua vim.diagnostic.goto_prev()<CR>", {})
----------------------------------------------------------------------------------
------------------------------- keymap for telescope ------------------------------
vim.keymap.set("n", "<leader>ff", builtin.find_files, {})
vim.keymap.set("n", "<leader>fb", builtin.buffers, {})
vim.keymap.set("n", "<leader>fn", builtin.tags, {})
vim.keymap.set("n", "<leader>fs", builtin.search_history, {})
vim.keymap.set("n", "<leader>fe", builtin.resume, {})
vim.keymap.set("n", "<leader>fp", builtin.pickers, {})
vim.keymap.set("n", "<leader>fk", builtin.keymaps, {})
vim.keymap.set("n", "<leader>fc", builtin.colorscheme, {})
vim.keymap.set("n", "<leader>fo", builtin.oldfiles, {})
vim.keymap.set("n", "<leader>fq", builtin.quickfix, {})
vim.keymap.set("n", "<leader>fi", builtin.registers, {})
vim.keymap.set("n", "<leader>fy", builtin.autocommands, {})
vim.keymap.set("n", "<leader>fz", builtin.command_history, {})
vim.keymap.set("n", "<leader>fh", ":Telescope help_tags theme=ivy<CR>")
vim.keymap.set("n", "<leader>fm", ":Telescope marks theme=ivy<CR>")
vim.keymap.set("n", "<leader>fw", ":Telescope buffers theme=ivy<CR>")
vim.keymap.set("n", "<leader>fg", ":Telescope live_grep theme=ivy<CR>")
vim.keymap.set("n", "<leader>fd", ":Telescope diagnostics theme=ivy<CR>")
vim.keymap.set("n", "<leader>fu", ":Telescope autocommands theme=ivy<CR>")
vim.keymap.set("n", "<leader>fr", ":Telescope live_grep theme=dropdown<CR>", {})
vim.keymap.set("n", "<leader>fx", ":Telescope find_files theme=ivy<CR>", {})
vim.keymap.set("n", "<leader>ft", ":Telescope find_files hidden=true<CR>", {})
vim.keymap.set("n", "<leader>fa", ":Telescope find_files find_command=rg,--ignore,--hidden,--files,-u<CR>", {})
-------------------------------------------------------------------------------------------
---------------------------------- keymap for lsp-buffer ----------------------------------
vim.keymap.set("n", "K", vim.lsp.buf.hover, {})
vim.keymap.set("n", "gd", vim.lsp.buf.definition, {})
vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, {})
-------------------------------------------------------------------------------------------
---------------------------------- keymap for none-ls -------------------------------------
vim.keymap.set("n", "<leader>gf", vim.lsp.buf.format, {})
vim.keymap.set("v", "<Leader>1f", vim.lsp.buf.format, {})
-------------------------------------------------------------------------------------------
---------------------------------- keymap for harpoon -------------------------------------
vim.keymap.set("n", "<leader>th", ":Telescope harpoon marks<CR>", {})
vim.keymap.set("n", "<C-j>", require("harpoon.ui").nav_prev) -- navigates to previous mark
vim.keymap.set("n", "<C-k>", require("harpoon.ui").nav_next) -- navigates to next mark
vim.keymap.set("n", "<C-q>", require("harpoon.ui").nav_next) -- navigates to next mark
vim.keymap.set("n", "<leader>z", require("harpoon.ui").toggle_quick_menu, {})
vim.keymap.set("n", "m1", ':lua require("harpoon.ui").nav_file(1)<CR>', { silent = true })
vim.keymap.set("n", "m2", ':lua require("harpoon.ui").nav_file(2)<CR>', { silent = true })
vim.keymap.set("n", "m3", ':lua require("harpoon.ui").nav_file(3)<CR>', { silent = true })
vim.keymap.set("n", "m4", ':lua require("harpoon.ui").nav_file(4)<CR>', { silent = true })
vim.keymap.set("n", "m5", ':lua require("harpoon.ui").nav_file(5)<CR>', { silent = true })
vim.keymap.set("n", "m6", ':lua require("harpoon.ui").nav_file(6)<CR>', { silent = true })
vim.keymap.set("n", "m7", ':lua require("harpoon.ui").nav_file(7)<CR>', { silent = true })
vim.keymap.set("n", "m8", ':lua require("harpoon.ui").nav_file(8)<CR>', { silent = true })
vim.keymap.set("n", "m9", ':lua require("harpoon.ui").nav_file(9)<CR>', { silent = true })
vim.keymap.set("n", "<leader>hh", function()
require("harpoon.mark").add_file()
vim.cmd("edit")
end, {})
-------------------------------------------------------------------------------------------
---------------------------------- Harpoon Theme customize --------------------------------
vim.cmd("highlight! HarpoonInactive guibg=NONE guifg=#63698c")
vim.cmd("highlight! HarpoonActive guibg=NONE guifg=white")
vim.cmd("highlight! HarpoonNumberActive guibg=NONE guifg=#7aa2f7")
vim.cmd("highlight! HarpoonNumberInactive guibg=NONE guifg=#7aa2f7")
vim.cmd("highlight! TabLineFill guibg=#d9280d guifg=#d9280d")
-------------------------------------------------------------------------------------------
---------------------------------- keymap for toggle-term ---------------------------------
vim.keymap.set("n", "<leader>cf", ":ToggleTerm direction=float size=20<CR>", {})
vim.keymap.set("n", "<leader>cv", ":ToggleTerm direction=vertical size=60<CR>", {})
vim.keymap.set("n", "<leader>ch", ":ToggleTerm direction=horizontal size=12<CR>", {})
-------------------------------------------------------------------------------------------
------------------------------- keymap for buffer navigation ------------------------------
vim.keymap.set("n", "<leader>we", ":bnext<CR>", {})
vim.keymap.set("n", "<leader>wq", ":bprev<CR>", {})
-------------------------------------------------------------------------------------------
------------------------------- keymap for tab navigation ---------------------------------
vim.keymap.set("n", "<leader>tt", ":tabnext<CR>", {}) -- next tab
vim.keymap.set("n", "<leader>ty", ":tabnext<CR>", {}) -- next tab
vim.keymap.set("n", "<leader>tr", ":tabprevious<CR>", {}) -- previous tab
vim.keymap.set("n", "<leader>tc", ":tabclose<CR>", {}) -- next tab
-------------------------------------------------------------------------------------------
--------------------------------- window binding in a tab ---------------------------------
vim.keymap.set("n", "<leader>ba", function()
local curr_line_num = tostring(vim.api.nvim__buf_stats(0).current_lnum)
vim.cmd("windo" .. " " .. curr_line_num)
vim.cmd("windo set cursorbind cursorline")
vim.notify("Binded all Windows in this tab")
end, {})
vim.keymap.set("n", "<leader>bn", function()
vim.cmd("windo set nocursorbind nocursorline")
vim.notify("Unbinded all Windows in this tab")
end, {})
--------------------------------------------------------------------------------------------
------------------------------- Accidental closing prevention ------------------------------
vim.keymap.set("n", "<c-z>", function()
vim.notify("you just got saved from an unwanted headache !!!!!")
end, {})
--------------------------------------------------------------------------------------------
vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN })
vim.diagnostic.get(0, {
severity = {
vim.diagnostic.severity.WARN,
vim.diagnostic.severity.INFO,
},
})
-- It's good practice to namespace custom handlers to avoid collisions
vim.diagnostic.handlers["my/notify"] = {
show = function(namespace, bufnr, diagnostics, opts)
-- In our example, the opts table has a "log_level" option
local level = opts["my/notify"].log_level
local name = vim.diagnostic.get_namespace(namespace).name
local msg = string.format("%d diagnostics in buffer %d from %s", #diagnostics, bufnr, name)
vim.notify(msg, level)
end,
}
-- Users can configure the handler
vim.diagnostic.config({
["my/notify"] = {
log_level = vim.log.levels.INFO,
},
})
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.highlight.on_yank()
end,
})
require("mason").setup({
ui = {
icons = {
package_installed = "✓",
package_pending = "➜",
package_uninstalled = "",
},
},
})
-- Neovim 0.11+ LSP configuration using vim.lsp.config
-- IMPORTANT: Must be defined BEFORE mason-lspconfig.setup() for automatic_enable to work
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)
-- LSP servers with custom settings
vim.lsp.config("lua_ls", {
capabilities = capabilities,
settings = {
Lua = {
hint = { enable = true },
diagnostics = { disable = { "missing-fields" } },
},
},
})
vim.lsp.config("ts_ls", {
capabilities = capabilities,
settings = {
typescript = {
inlayHints = {
includeInlayParameterNameHints = "all",
includeInlayParameterNameHintsWhenArgumentMatchesName = true,
includeInlayFunctionParameterTypeHints = true,
includeInlayVariableTypeHints = true,
includeInlayVariableTypeHintsWhenTypeMatchesName = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayEnumMemberValueHints = true,
},
},
javascript = {
inlayHints = {
includeInlayParameterNameHints = "all",
includeInlayParameterNameHintsWhenArgumentMatchesName = true,
includeInlayFunctionParameterTypeHints = true,
includeInlayVariableTypeHints = true,
includeInlayVariableTypeHintsWhenTypeMatchesName = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayEnumMemberValueHints = true,
},
},
},
on_attach = function(client)
client.server_capabilities.documentFormattingProvider = false
client.server_capabilities.documentRangeFormattingProvider = false
end,
})
vim.lsp.config("pylsp", {
capabilities = capabilities,
settings = {
pylsp = { plugins = { pycodestyle = { maxLineLength = 150 } } },
},
})
-- LSP servers with default capabilities only
local simple_servers = {
"rust_analyzer",
"quick_lint_js",
-- "eslint",
"taplo",
"html",
"lwc_ls",
"cssls",
"jsonls",
"vue_ls",
"angularls",
"clangd",
"sqls",
"emmet_ls",
"gopls",
"dartls",
"bashls",
-- "ltex",
"vimls",
"yamlls",
"vale_ls",
"intelephense",
"diagnosticls",
"jedi_language_server",
"twiggy_language_server",
}
for _, server in ipairs(simple_servers) do
vim.lsp.config(server, { capabilities = capabilities })
end
-- Now setup mason-lspconfig AFTER configs are defined
require("mason-lspconfig").setup({
ensure_installed = {
"lua_ls",
"rust_analyzer",
"quick_lint_js",
-- "eslint",
"ts_ls",
"html",
"lwc_ls",
"jsonls",
"cssls",
"vimls",
"emmet_ls",
"vue_ls",
"angularls",
"clangd",
"sqls",
"taplo",
"pylsp",
"gopls",
"bashls",
"ltex",
"yamlls",
"vale_ls",
"intelephense",
"diagnosticls",
"jedi_language_server",
"twiggy_language_server",
},
-- Disable automatic_enable - we'll manually enable servers
automatic_enable = false,
})
-- Manually enable all configured LSP servers AFTER configs are defined
vim.lsp.enable({
"lua_ls",
"ts_ls",
"pylsp",
"rust_analyzer",
"quick_lint_js",
"taplo",
"html",
"lwc_ls",
"cssls",
"jsonls",
"vue_ls",
"angularls",
"clangd",
"sqls",
"emmet_ls",
"gopls",
"dartls",
"bashls",
"vimls",
"yamlls",
"vale_ls",
"intelephense",
"diagnosticls",
"jedi_language_server",
"twiggy_language_server",
})
-- Auto-install formatters and linters (NOT LSP servers - those are handled by mason-lspconfig)
require("mason-tool-installer").setup({
ensure_installed = {
-- Formatters
"stylua", -- Lua
"prettier", -- JS/TS/CSS/JSON/HTML
"prettierd", -- Faster prettier daemon
"htmlbeautifier", -- HTML
"shfmt", -- Shell
"yamlfmt", -- YAML
"gofumpt", -- Go
"golines", -- Go line length
-- Linters
"shellcheck", -- Shell
"shellharden", -- Shell
"luacheck", -- Lua
"vint", -- Vimscript
"gitlint", -- Git commits
"gitleaks", -- Git secrets detection
"editorconfig-checker",
},
auto_update = false,
run_on_start = true,
start_delay = 3000,
debounce_hours = 5,
-- Disable integrations for plugins we don't have installed
integrations = {
["mason-lspconfig"] = true,
["mason-null-ls"] = true,
["mason-nvim-dap"] = false, -- Not using DAP
},
})
local null_ls = require("null-ls")
local h = require("null-ls.helpers")
-- local cmd_resolver = require("null-ls.helpers.command_resolver")
local methods = require("null-ls.methods")
-- local u = require("null-ls.utils")
local FORMATTING = methods.internal.FORMATTING
local RANGE_FORMATTING = methods.internal.RANGE_FORMATTING
null_ls.setup({
sources = {
null_ls.builtins.formatting.stylua,
null_ls.builtins.formatting.htmlbeautifier,
null_ls.builtins.formatting.prettier.with({
filetypes = {
"css",
"json",
"javascript",
"typescript",
".prettierrc",
"javascriptreact",
"typescriptreact",
},
method = { FORMATTING, RANGE_FORMATTING },
-- generator_opts = {
-- command = "prettier",
-- args = h.range_formatting_args_factory({
-- "--stdin-filepath",
-- "$FILENAME",
-- }, "--range-start", "--range-end", { row_offset = -1, col_offset = -1 }),
-- "--tab-width",
-- "-1",
-- "--use-tabs",
-- to_stdin = true,
-- dynamic_command = cmd_resolver.from_node_modules(),
-- cwd = h.cache.by_bufnr(function(params)
-- return u.root_pattern(
-- -- https://prettier.io/docs/en/configuration.html
-- ".prettierrc",
-- ".prettierrc.json",
-- ".prettierrc.yml",
-- ".prettierrc.yaml",
-- ".prettierrc.json5",
-- ".prettierrc.js",
-- ".prettierrc.cjs",
-- ".prettierrc.toml",
-- "prettier.config.js",
-- "prettier.config.cjs",
-- "package.json"
-- )(params.bufname)
-- end),
-- },
factory = h.formatter_factory,
}),
null_ls.builtins.formatting.shellharden,
null_ls.builtins.formatting.shfmt,
null_ls.builtins.formatting.yamlfmt,
null_ls.builtins.code_actions.gitsigns,
},
-- on_attach = function(current_client, bufnr)
-- if current_client.supports_method("textDocument/formatting") then
-- vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
-- vim.api.nvim_create_autocmd("BufWritePre", {
-- group = augroup,
-- buffer = bufnr,
-- callback = function()
-- vim.lsp.buf.format({
-- filter = function(client)
-- -- only use null-ls for formatting instead of lsp server
-- return client.name == "null-ls"
-- end,
-- bufnr = bufnr,
-- })
-- end,
-- })
-- end
-- end,
})
-- vim.lsp.buf.format({
-- filter = function(client)
-- -- only use null-ls for formatting instead of lsp server
-- return client.name == "quick_lint_js"
-- end,
-- })
-- local formatting = null_ls.builtins.formatting
-- null_ls.setup({
-- sources = {
-- formatting.prettier.with({
-- filetypes = { "javascript", "typescript", "html", "css", "json" },
-- -- set tab width to 2 and use tabs instead of spaces
-- args = { "--stdin-filepath", "$FILENAME", "--tab-width", "1", "--use-tabs" },
-- }),
-- },
-- })
local cmp = require("cmp")
require("luasnip.loaders.from_vscode").lazy_load()
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
require("luasnip").lsp_expand(args.body) -- For `luasnip` users.
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" }, -- For luasnip users.
{ name = "vim-dadbod-completion" },
{ name = "nvim_lua" },
{ name = "path" },
{ name = "buffer", keyword_length = 5 },
}, {
{ name = "buffer" },
}),
cmp.setup.filetype("gitcommit", {
sources = cmp.config.sources({
{ name = "cmp_git" }, -- You can specify the `cmp_git` source if you were installed it.
}, {
{ name = "buffer" },
}),
}),
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
-- cmp.setup.cmdline("/", {
-- mapping = cmp.mapping.preset.cmdline(),
-- sources = {
-- { name = "buffer" },
-- },
-- }),
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
-- cmp.setup.cmdline(":", {
-- sources = cmp.config.sources({
-- { name = "path" },
-- }, {
-- { name = "cmdline" },
-- }),
-- }),
})
-- require("cmp").setup.buffer({ sources = { { name = "vim-dadbod-completion" } } })
vim.keymap.set("n", "<leader>ih", function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({}))
local message
if const.inlay_hint_msg_toggle == 0 then
const.inlay_hint_msg_toggle = 1
message = "Inlay Hint Activated"
else
const.inlay_hint_msg_toggle = 0
message = "Inlay Hint Deactivated"
end
vim.notify(message)
end)
require("telescope").setup({
extensions = {
["ui-select"] = {
require("telescope.themes").get_dropdown({}),
},
},
defaults = {
defaults = {
-- layout_config = {
-- preview_cutoff = 250, -- Adjust this value to increase or decrease the size
-- },
},
-- mappings = { default_mappings = config.values.default_mappings },
history = {
path = "~/.local/share/nvim/databases/telescope_history.sqlite3",
limit = 100,
},
file_ignore_patterns = { "node_modules/.*" },
},
})
require("telescope").load_extension("ui-select")
-- require('telescope').load_extension('smart_history')
vim.cmd.colorscheme("catppuccin")
vim.cmd([[
highlight LineNr guifg=#C4913A gui=bold " Color: Satin Sheen Gold
highlight LineNrAbove guifg=#708090 " Color: Slate Grey
highlight LineNrBelow guifg=#708090 " Color: Slate Grey
]])
vim.api.nvim_create_user_command("Cppath", function()
local path = vim.fn.expand("%:p")
vim.fn.setreg("+", path)
vim.notify('Copied "' .. path .. '" to the clipboard!')
end, {})
vim.api.nvim_create_user_command("Ppath", function()
local path = vim.fn.expand("%")
vim.notify(path)
end, {})
vim.api.nvim_create_user_command("Tc", function()
vim.cmd("tabclose")
end, {})
vim.api.nvim_create_user_command("Gcclog", function()
vim.cmd("tabnew | Gclog")
end, {})
require("nvim-autopairs").setup({
disable_filetype = { "TelescopePrompt", "vim" },
check_ts = true,
ts_config = {
lua = { "string" }, -- it will not add a pair on that treesitter node
javascript = { "template_string" },
java = false, -- don't check treesitter on java
},
})
local Rule = require("nvim-autopairs.rule")
local ts_conds = require("nvim-autopairs.ts-conds")
require("nvim-autopairs").add_rules({
Rule("%", "%", "lua"):with_pair(ts_conds.is_ts_node({ "string", "comment" })),
Rule("$", "$", "lua"):with_pair(ts_conds.is_not_ts_node({ "function" })),
})
require("nvim-surround").setup({
-- Configuration here, or leave empty to use defaults
})
function _G.set_terminal_keymaps()
local opts = { buffer = 0 }
vim.keymap.set("t", "<esc>", [[<C-\><C-n>]], opts)
-- vim.keymap.set("t", "jk", [[<C-\><C-n>]], opts)
vim.keymap.set("t", "<C-h>", [[<Cmd>wincmd h<CR>]], opts)
vim.keymap.set("t", "<C-j>", [[<Cmd>wincmd j<CR>]], opts)
-- vim.keymap.set("t", "<C-k>", [[<Cmd>wincmd k<CR>]], opts)
vim.keymap.set("t", "<C-l>", [[<Cmd>wincmd l<CR>]], opts)
-- vim.keymap.set("t", "<C-w>", [[<C-\><C-n><C-w>]], opts)
end
-- if you only want these mappings for toggle term use term://*toggleterm#* instead
vim.cmd("autocmd! TermOpen term://* lua set_terminal_keymaps()")
-- require("ts_context_commentstring").setup({
-- enable_autocmd = false,
-- })
local Harpoon = require("harpoon")
Harpoon.setup({
tabline = true,
tabline_prefix = " ",
tabline_suffix = " ",
global_settings = {
-- sets the marks upon calling `toggle` on the ui, instead of require `:w`.
save_on_toggle = true,
-- saves the harpoon file upon every change. disabling is unrecommended.
save_on_change = true,
-- sets harpoon to run the command immediately as it's passed to the terminal when calling `sendCommand`.
enter_on_sendcmd = false,
-- closes any tmux windows harpoon that harpoon creates when you close Neovim.
tmux_autoclose_windows = false,
-- filetypes that you want to prevent from adding to the harpoon list menu.
excluded_filetypes = { "harpoon" },
-- set marks specific to each git branch inside git repository
mark_branch = false,
-- enable tabline with harpoon marks
-- tabline = true,
-- tabline_prefix = " hellow ",
-- tabline_suffix = " world ",
},
menu = {
width = vim.api.nvim_win_get_width(0) - 30,
height = vim.api.nvim_win_get_height(0) - 18,
},
})
vim.g.lazydev_enabled = true
-- local file_path = "output.txt"
-- local file = io.open(file_path, "w") -- "w" mode is for writing (will overwrite the file)
--
-- if file then
-- local rrr = vim.inspect(package.loaded)
-- file:write(rrr)
-- file:close() -- Don't forget to close the file!
-- else
-- print("Could not open file for writing.")
-- end
-- Function to handle keypress
-- local function track_keypress(key)
-- print("Key pressed: " .. vim.api.nvim_replace_termcodes(key, true, true, true))
-- end
--
-- -- Set up the keypress tracker
-- vim.on_key(track_keypress)
-- local fn = require("utils.fn")
-- Function to log command-line inputs
-- local function log_cmdline_input()
-- if file th
-- local rrr = vim.inspect(vim.fn.getcmdline())
-- file:write(rrr)
-- file:close() -- Don't forget to close the file!
-- else
-- print("Could not open file for writing.")
-- end
-- if cmdline == "G<CR>" or cmdline == ":G<CR>" then
-- fn.create_float_window_V2({ tostring("hello") }, {})
-- end
-- end
-- Set up autocommands for command-line mode
-- vim.api.nvim_create_autocmd("CmdlineEnter", {
-- callback = log_cmdline_input,
-- })
-- vim.api.nvim_create_autocmd("CmdlineLeave:", {
-- callback = function()
-- print("Exiting command-line mode")
-- end
-- })
-- vim.api.nvim_create_autocmd({ "CmdlineChanged", "CmdlineEnter" }, {
-- callback = function()
-- local str, chk = vim.fn.getcmdline():gsub("", "")
-- if chk > 1 then
-- local fh = io.open("nvim_cmd.log", "a+")
-- fh:write(("%s%s%s\n"):format(vim.fn.getcmdtype(), " hello ", str))
-- fh:flush()
-- end
-- end,
-- })
-- vim.api.nvim_create_autocmd("CursorMoved", {
-- pattern = "*",
-- callback = function()
-- local cursor_pos = vim.api.nvim_win_get_cursor(0) -- 0 refers to the current window
-- vim.print("Cursor moved in normal mode" .. tostring(vim.inspect(cursor_pos)))
-- end,
-- })
-- vim.api.nvim_create_autocmd("WinClosed", {
-- callback = function(event)
-- vim.print("Window closed with buffer number:" .. " " .. event.buf)
-- end,
-- })
--
-- Disable warnings for .env files only, keep errors and info visible
vim.api.nvim_create_autocmd({ "BufRead", "BufEnter" }, {
pattern = "*.env",
callback = function()
vim.diagnostic.config({
virtual_text = {
severity = {
min = vim.diagnostic.severity.ERROR, -- Show only errors and info, hide warnings
},
},
signs = true, -- Keep signs (gutter indicators) for errors and info
underline = true, -- Keep underlining for errors and info
update_in_insert = false, -- Optional: prevent updates during insert mode
})
end,
})
vim.api.nvim_create_user_command("DeleteFile", function()
local file = vim.fn.expand("%:p") -- Get the full path of the current file
if vim.fn.confirm("Delete " .. file .. "?", "&Yes\n&No", 2) == 1 then
vim.fn.delete(file) -- Delete the file
vim.cmd("bd") -- Close the buffer
end
end, {})
vim.api.nvim_create_user_command("RenameFile", function(opts)
local old_name = vim.fn.expand("%")
local new_name = opts.args
if vim.fn.rename(old_name, new_name) == 0 then
vim.cmd("e " .. new_name)
vim.cmd("bwipeout " .. old_name)
print("Renamed " .. old_name .. " to " .. new_name)
else
print("Failed to rename " .. old_name)
end
end, { nargs = 1 })
-- Keymaps to mark the cursor's current position before executing the following commands.
-- This allows you to return to the marked position after the command is executed (if desired).
local cursor_track_cmds = { "gg", "G", "vap", "v{", "v}", "{", "}", "v/{", "v/}" }
for _, value in ipairs(cursor_track_cmds) do
vim.keymap.set("n", value, function()
local cur_pos = vim.api.nvim_win_get_cursor(0)
vim.api.nvim_set_var("last_cursor_pos", cur_pos)
vim.api.nvim_exec2("mark l", { output = false })
vim.api.nvim_exec2("normal!" .. " " .. value, { output = false })
end, { silent = true })
end
-- Keymap to jump to the exact line and column the cursor was at before executing the tracked commands
vim.keymap.set("n", "<leader>ll", function()
local last_pos = vim.api.nvim_get_var("last_cursor_pos")
if last_pos then
vim.api.nvim_win_set_cursor(0, last_pos)
end
end, { noremap = true, silent = true })