-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathinit.lua
More file actions
577 lines (514 loc) · 14.4 KB
/
init.lua
File metadata and controls
577 lines (514 loc) · 14.4 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
-- Install package manager
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.uv.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)
--Remap space as leader key
vim.keymap.set({ "n", "v" }, "<Space>", "<Nop>", { silent = true })
vim.g.mapleader = " "
vim.g.maplocalleader = " "
-- Add plugins
require("lazy").setup({
{ "kylechui/nvim-surround", config = true },
"tpope/vim-sleuth",
{
"linrongbin16/gitlinker.nvim",
cmd = "GitLink",
opts = {},
keys = {
{ "<leader>gy", "<cmd>GitLink<cr>", mode = { "n", "v" }, desc = "Yank git link" },
{ "<leader>gY", "<cmd>GitLink!<cr>", mode = { "n", "v" }, desc = "Open git link" },
},
},
{ "brenoprata10/nvim-highlight-colors", config = true },
"stevearc/oil.nvim",
"mrjones2014/smart-splits.nvim",
"nvim-lualine/lualine.nvim",
{ "j-hui/fidget.nvim", config = true },
"lukas-reineke/indent-blankline.nvim",
"lewis6991/gitsigns.nvim",
{
"zbirenbaum/copilot.lua",
cmd = "Copilot",
event = "InsertEnter",
config = function()
require("copilot").setup({
suggestion = { enabled = false },
panel = { enabled = false },
})
end,
},
{
"olimorris/codecompanion.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter",
},
config = true,
},
"neovim/nvim-lspconfig",
{
"NeogitOrg/neogit",
dependencies = {
"nvim-lua/plenary.nvim", -- required
"sindrets/diffview.nvim", -- optional
"ibhagwan/fzf-lua", -- optional
},
opts = {
integrations = {
diffview = true,
},
},
},
{
"olimorris/onedarkpro.nvim",
priority = 1000, -- Ensure it loads first
},
{
"stevearc/quicker.nvim",
event = "FileType qf",
---@module "quicker"
---@type quicker.SetupOptions
opts = {},
},
{
"ibhagwan/fzf-lua",
-- optional for icon support
dependencies = { "nvim-tree/nvim-web-devicons" },
-- or if using mini.icons/mini.nvim
-- dependencies = { "echasnovski/mini.icons" },
opts = {},
},
"giuxtaposition/blink-cmp-copilot",
{
"saghen/blink.cmp",
-- optional: provides snippets for the snippet source
dependencies = { "rafamadriz/friendly-snippets" },
-- use a release tag to download pre-built binaries
version = "*",
---@module 'blink.cmp'
---@type blink.cmp.Config
opts = {
-- Default list of enabled providers defined so that you can extend it
-- elsewhere in your config, without redefining it, due to `opts_extend`
sources = {
default = { "lsp", "path", "snippets", "buffer", "copilot" },
providers = {
copilot = {
name = "copilot",
module = "blink-cmp-copilot",
score_offset = 100,
async = true,
},
},
},
keymap = { preset = "super-tab" },
completion = {
ghost_text = {
enabled = true,
},
},
},
opts_extend = { "sources.default" },
},
"stevearc/conform.nvim",
"mfussenegger/nvim-lint",
{
-- Highlight, edit, and navigate code
"nvim-treesitter/nvim-treesitter",
dependencies = {
"nvim-treesitter/nvim-treesitter-textobjects",
},
},
{
"Wansmer/treesj",
dependencies = { "nvim-treesitter/nvim-treesitter" },
},
}, {})
--Set highlight on search
vim.o.hlsearch = false
--Make line numbers default
vim.wo.number = true
--Enable break indent
vim.o.breakindent = true
--Save undo history
vim.opt.undofile = true
--Case insensitive searching UNLESS /C or capital in search
vim.o.ignorecase = true
vim.o.smartcase = true
-- Keep signcolumn on by default
vim.wo.signcolumn = "yes"
-- Decrease update time
vim.o.updatetime = 250
--Set colorscheme (order is important here)
vim.cmd("colorscheme onedark")
local onedark = require("lualine.themes.onedark")
for _, mode in pairs(onedark) do
mode.a.gui = nil
end
--Set statusbar
require("lualine").setup({
options = {
icons_enabled = false,
theme = onedark,
component_separators = "|",
section_separators = "",
globalstatus = true,
},
sections = {
lualine_a = { "mode" },
lualine_b = { "filename" },
lualine_c = { "lsp_progress" },
lualine_x = { "filetype" },
lualine_y = { "progress" },
lualine_z = { "location" },
},
})
-- Other package managers
require("codecompanion").setup({})
vim.keymap.set("n", "<leader>q", function()
require("quicker").toggle()
end, {
desc = "Toggle quickfix",
})
vim.keymap.set("n", "<leader>l", function()
require("quicker").toggle({ loclist = true })
end, {
desc = "Toggle loclist",
})
require("quicker").setup({
keys = {
{
">",
function()
require("quicker").expand({ before = 2, after = 2, add_to_existing = true })
end,
desc = "Expand quickfix context",
},
{
"<",
function()
require("quicker").collapse()
end,
desc = "Collapse quickfix context",
},
},
})
vim.cmd([[ command! DiffviewFile execute("DiffviewOpen -- " . expand("%")) | DiffviewToggleFiles]])
--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 })
--Add move line shortcuts
vim.keymap.set("n", "<A-j>", ":m .+1<CR>==")
vim.keymap.set("n", "<A-k>", ":m .-2<CR>==")
vim.keymap.set("i", "<A-j>", "<Esc>:m .+1<CR>==gi")
vim.keymap.set("i", "<A-k>", "<Esc>:m .-2<CR>==gi")
vim.keymap.set("v", "<A-j>", ":m '>+1<CR>gv=gv")
vim.keymap.set("v", "<A-k>", ":m '<-2<CR>gv=gv")
--Remap escape to leave terminal mode
vim.keymap.set("t", "<Esc>", [[<c-\><c-n>]])
--Disable numbers in terminal mode
local terminal_group = vim.api.nvim_create_augroup("Terminal", { clear = true })
vim.api.nvim_create_autocmd("TermOpen", { command = "set nonu", group = terminal_group })
require("ibl").setup({
indent = { char = "┊" },
-- filetype_exclude = { 'help' },
-- buftype_exclude = { 'terminal', 'nofile' },
whitespace = {
remove_blankline_trail = false,
},
})
-- Gitsigns
require("gitsigns").setup({
signs = {
add = { text = "+" },
change = { text = "~" },
delete = { text = "_" },
topdelete = { text = "‾" },
changedelete = { text = "~" },
},
on_attach = function(bufnr)
vim.keymap.set("n", "[c", require("gitsigns").prev_hunk, { buffer = bufnr })
vim.keymap.set("n", "]c", require("gitsigns").next_hunk, { buffer = bufnr })
end,
})
-- Better netrw replacement
require("oil").setup({
view_options = {
show_hidden = true,
},
})
-- Better splitjoin replacement
require("treesj").setup({})
vim.keymap.set("n", "U", require("treesj").toggle)
-- Smart splits
require("smart-splits").setup()
-- for example `10<A-h>` will `resize_left` by `(10 * config.default_amount)`
vim.keymap.set("n", "<A-h>", require("smart-splits").resize_left)
vim.keymap.set("n", "<A-j>", require("smart-splits").resize_down)
vim.keymap.set("n", "<A-k>", require("smart-splits").resize_up)
vim.keymap.set("n", "<A-l>", require("smart-splits").resize_right)
-- moving between splits
vim.keymap.set("n", "<C-h>", require("smart-splits").move_cursor_left)
vim.keymap.set("n", "<C-j>", require("smart-splits").move_cursor_down)
vim.keymap.set("n", "<C-k>", require("smart-splits").move_cursor_up)
vim.keymap.set("n", "<C-l>", require("smart-splits").move_cursor_right)
vim.keymap.set("n", "<C-\\>", require("smart-splits").move_cursor_previous)
-- swapping buffers between windows
vim.keymap.set("n", "<leader><leader>h", require("smart-splits").swap_buf_left)
vim.keymap.set("n", "<leader><leader>j", require("smart-splits").swap_buf_down)
vim.keymap.set("n", "<leader><leader>k", require("smart-splits").swap_buf_up)
vim.keymap.set("n", "<leader><leader>l", require("smart-splits").swap_buf_right)
-- Oil
vim.keymap.set("n", "-", function()
require("oil").open()
end, { desc = "Open parent directory" })
-- Managing buffers
vim.keymap.set("n", "<leader>bd", ":bdelete<CR>", { silent = true })
-- Random
vim.keymap.set("n", "<leader>;", ":")
-- remove conceal on markdown files
vim.g.markdown_syntax_conceal = 0
-- Change preview window location
vim.g.splitbelow = true
-- Remap number increment to alt
vim.keymap.set("n", "<A-a>", "<C-a>")
vim.keymap.set("v", "<A-a>", "<C-a>")
vim.keymap.set("n", "<A-x>", "<C-x>")
vim.keymap.set("v", "<A-x>", "<C-x>")
-- n always goes forward
vim.keymap.set("n", "n", "'Nn'[v:searchforward]", { expr = true })
vim.keymap.set("x", "n", "'Nn'[v:searchforward]", { expr = true })
vim.keymap.set("o", "n", "'Nn'[v:searchforward]", { expr = true })
vim.keymap.set("n", "N", "'nN'[v:searchforward]", { expr = true })
vim.keymap.set("x", "N", "'nN'[v:searchforward]", { expr = true })
vim.keymap.set("o", "N", "'nN'[v:searchforward]", { expr = true })
-- map :W to :w (helps which-key issue)
vim.cmd([[ command! W execute ':w' ]])
-- Neovim python support
vim.g.loaded_python_provider = 0
-- 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 = "*",
})
-- Clear white space on empty lines and end of line
vim.keymap.set(
"n",
"<F6>",
[[:let _s=@/ <Bar> :%s/\s\+$//e <Bar> :let @/=_s <Bar> :nohl <Bar> :unlet _s <CR>]],
{ silent = true }
)
-- Fzf Lua bindings
vim.keymap.set("n", "<leader>f", require("fzf-lua").files)
vim.keymap.set("n", "<leader>?", require("fzf-lua").oldfiles)
vim.keymap.set("n", "<leader><leader>", require("fzf-lua").buffers)
vim.keymap.set("n", "<leader>,", require("fzf-lua").live_grep_native)
-- Treesitter configuration
-- Parsers must be installed manually via :TSInstall
require("nvim-treesitter.configs").setup({
ensure_installed = { "c", "cpp", "go", "lua", "python", "rust", "just", "tsx", "typescript", "vim" },
auto_install = false,
highlight = {
enable = true, -- false will disable the whole extension
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<c-space>",
node_incremental = "<c-space>",
scope_incremental = "<c-s>",
node_decremental = "<M-space>",
},
},
indent = {
enable = true,
disable = { "org" },
},
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 = {
["<leader>pa"] = "@parameter.inner",
},
swap_previous = {
["<leader>pA"] = "@parameter.inner",
},
},
},
})
-- Diagnostic settings
vim.diagnostic.config({
signs = true,
update_in_insert = true,
})
-- Diagnostic keymaps
vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float)
-- vim.keymap.set("n", "<leader>qd", vim.diagnostic.setqflist)
-- Formatter configuration
require("conform").setup({
formatters_by_ft = {
lua = { "stylua" },
-- Conform will run multiple formatters sequentially
python = { "ruff" },
-- Use a sub-list to run only the first available formatter
javascript = { "prettierd", "prettier" },
},
})
vim.api.nvim_create_user_command("Format", function(args)
local range = nil
if args.count ~= -1 then
local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1]
range = {
start = { args.line1, 0 },
["end"] = { args.line2, end_line:len() },
}
end
require("conform").format({ async = true, lsp_format = "fallback", range = range })
end, { range = true })
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
require("lint").linters_by_ft = {
python = { "ruff" },
}
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
callback = function()
require("lint").try_lint()
end,
})
-- LSP settings
-- log file location: $HOME/.cache/nvim/lsp.log
-- Add nvim-lspconfig plugin
local lspconfig = require("lspconfig")
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
local bufnr = ev.buf
local attach_opts = { silent = true, buffer = bufnr }
-- Mappings.
vim.keymap.set("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, attach_opts)
vim.keymap.set("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, attach_opts)
vim.keymap.set("n", "<leader>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, attach_opts)
vim.keymap.set("n", "gt", vim.lsp.buf.type_definition, attach_opts)
if client.server_capabilities.documentFormattingProvider then
vim.keymap.set("n", "<leader>bf", vim.lsp.buf.format, attach_opts)
else
end
-- ...
end,
})
local capabilities = require("blink.cmp").get_lsp_capabilities()
vim.api.nvim_create_autocmd("User", {
pattern = "BlinkCmpMenuOpen",
callback = function()
require("copilot.suggestion").dismiss()
vim.b.copilot_suggestion_hidden = true
end,
})
vim.api.nvim_create_autocmd("User", {
pattern = "BlinkCmpMenuClose",
callback = function()
vim.b.copilot_suggestion_hidden = false
end,
})
local servers = {
"biome",
"pyrefly",
"yamlls",
"jsonls",
}
for _, lsp in ipairs(servers) do
vim.lsp.config(lsp, {
capabilities = capabilities,
handlers = handlers,
})
vim.lsp.enable(lsp)
end
vim.lsp.config("html", {
handlers = handlers,
capabilities = capabilities,
init_options = {
provideFormatter = true,
embeddedLanguages = { css = true, javascript = true },
configurationSection = { "html", "css", "javascript" },
},
})
vim.lsp.enable("html")
vim.lsp.config("lua_ls", {
handlers = handlers,
capabilities = capabilities,
settings = {
Lua = {
completion = {
callSnippet = "Replace",
},
},
},
})
vim.lsp.enable("lua_ls")
vim.lsp.config("typescript", {
cmd = { "tsgo", "--lsp", "--stdio" },
capabilities = capabilities,
filetypes = {
"javascript",
"javascriptreact",
"javascript.jsx",
"typescript",
"typescriptreact",
"typescript.tsx",
},
root_markers = {
"tsconfig.json",
"jsconfig.json",
"package.json",
".git",
"tsconfig.base.json",
},
})
vim.lsp.enable("typescript")