-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
619 lines (592 loc) · 17.6 KB
/
init.lua
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
-- leader -> space
vim.g.mapleader = " "
-- options
local o = vim.opt
o.backup = false
o.breakindent = true
o.clipboard = "unnamedplus"
o.conceallevel = 1
o.cursorline = true
o.expandtab = true
o.foldenable = false
o.foldmethod = "manual"
o.hlsearch = false
o.ignorecase = true
o.number = true
o.scrolloff = 8
o.shiftwidth = 4
o.signcolumn = "yes"
o.smartcase = true
o.smartindent = true
o.softtabstop = 4
o.spell = true
o.spelllang = "en_us"
o.swapfile = false
o.tabstop = 4
o.timeoutlen = 300
o.updatetime = 250
o.wrap = false
o.writebackup = false
-- plugins
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
o.rtp:prepend(lazypath)
require("lazy").setup {
-- lua style
{
"wesleimp/stylua.nvim",
},
-- treesitter
{
"nvim-treesitter/nvim-treesitter",
dependencies = {
"nvim-treesitter/nvim-treesitter-textobjects",
},
build = ":TSUpdate",
config = function()
local configs = require "nvim-treesitter.configs"
configs.setup {
ensure_installed = { "lua", "rust" },
sync_install = false,
highlight = { enable = true },
indent = { enable = true },
auto_install = true,
}
require("vim.treesitter.query").set(
"markdown",
"highlights",
"(fenced_code_block_delimiter) @punctuation.bracket"
)
end,
},
-- the format
{
"stevearc/conform.nvim",
config = function()
require("conform").setup {
formatters_by_ft = {
lua = { "stylua" },
rust = { "rustfmt", lsp_format = "fallback" },
},
format_on_save = {
timeout_ms = 500,
lsp_format = "fallback",
},
}
end,
},
-- the completion
{
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
},
config = function()
local cmp = require "cmp"
cmp.setup {
completion = {
completeopt = "menu,menuone,noinsert",
},
mapping = cmp.mapping.preset.insert {
["<C-j>"] = cmp.mapping.select_next_item(),
["<C-k>"] = cmp.mapping.select_prev_item(),
["<C-b>"] = 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()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end, { "i", "s" }),
},
sources = cmp.config.sources {
{
name = "nvim_lsp",
entry_filter = function(entry, _)
return require("cmp").lsp.CompletionItemKind.Snippet ~= entry:get_kind()
end,
},
{ name = "buffer" },
{ name = "path" },
},
window = {
documentation = cmp.config.window.bordered {
winhighlight = "Normal:CmpPmenu,FloatBorder:CmpBorder",
},
completion = cmp.config.window.bordered {
winhighlight = "Normal:CmpPmenu,FloatBorder:CmpBorder",
},
},
}
end,
},
-- LSP stuff
{
"williamboman/mason.nvim",
config = function()
require("mason").setup()
end,
},
{
"williamboman/mason-lspconfig.nvim",
config = function()
require("mason-lspconfig").setup {
ensure_installed = { "lua_ls", "taplo" },
}
end,
},
{
"neovim/nvim-lspconfig",
lazy = false,
config = function(_, _)
vim.diagnostic.config {
virtual_text = false,
severity_sort = true,
virtual_lines = { highlight_whole_line = false },
}
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local lspconfig = require "lspconfig"
lspconfig.lua_ls.setup {
capabilities = capabilities,
}
lspconfig.rust_analyzer.setup {
settings = {
["rust-analyzer"] = {
check = {
command = "clippy",
extraArgs = {
"--",
"-D",
"warnings",
"-D",
"clippy::unwrap_used",
"-D",
"clippy::expect_used",
"--no-deps",
},
},
checkOnSave = {
command = "clippy",
extraArgs = {
"--",
"-D",
"warnings",
"-D",
"clippy::unwrap_used",
"-D",
"clippy::expect_used",
"--no-deps",
},
},
cargo = {
allFeatures = true,
buildScripts = {
enable = true,
},
},
lens = {
enable = true,
},
semanticHighlighting = {
enable = true,
},
cachePriming = {
enable = true,
},
hover = {
actions = {
enable = true,
},
documentation = {
enable = true,
},
},
inlayHints = {
enable = true,
typeHints = true,
parameterHints = true,
},
diagnostics = {
experimental = {
enable = true,
},
},
procMacro = {
enable = true,
},
imports = {
group = {
enable = false,
},
},
completion = {
postfix = {
enable = false,
},
},
},
},
}
end,
},
{
"rust-lang/rust.vim",
ft = { "rust" },
config = function() end,
},
-- NOTE: switch to rustaceanvim in case any weird thing happen
-- {
-- "mrcjkb/rustaceanvim",
-- lazy = false,
-- ft = { "rust" },
-- config = function(_, opts)
-- vim.g.rustaceanvim = vim.tbl_deep_extend("force", {}, opts or {})
-- end,
-- opts = {
-- server = {
-- settings = {
-- ["rust-analyzer"] = {
-- check = {
-- command = "clippy",
-- extraArgs = {
-- "--",
-- "-D",
-- "warnings",
-- "-D",
-- "clippy::unwrap_used",
-- "-D",
-- "clippy::expect_used",
-- "--no-deps",
-- },
-- },
-- },
-- },
-- },
-- },
-- },
{
"nvimdev/lspsaga.nvim",
config = function()
require("lspsaga").setup {
symbol_in_winbar = {
enable = false,
},
lightbulb = {
enable = false,
},
}
end,
dependencies = {
"nvim-treesitter/nvim-treesitter",
},
},
-- the awesome mini
{
"echasnovski/mini.nvim",
config = function()
require("mini.align").setup()
require("mini.animate").setup()
require("mini.basics").setup()
require("mini.comment").setup()
require("mini.cursorword").setup()
require("mini.diff").setup()
require("mini.extra").setup()
require("mini.files").setup()
require("mini.git").setup()
require("mini.icons").setup()
require("mini.indentscope").setup()
require("mini.move").setup()
require("mini.notify").setup()
require("mini.pairs").setup()
require("mini.pick").setup()
require("mini.starter").setup()
require("mini.tabline").setup()
require("mini.trailspace").setup()
local statusline = require "mini.statusline"
statusline.setup { use_icons = true }
statusline.section_location = function()
return "%2l:%-2v"
end
local hipatterns = require "mini.hipatterns"
hipatterns.setup {
highlighters = {
fixme = { pattern = "%f[%w]()FIXME()%f[%W]", group = "MiniHipatternsFixme" },
hack = { pattern = "%f[%w]()HACK()%f[%W]", group = "MiniHipatternsHack" },
todo = { pattern = "%f[%w]()TODO()%f[%W]", group = "MiniHipatternsTodo" },
note = { pattern = "%f[%w]()NOTE()%f[%W]", group = "MiniHipatternsNote" },
hex_color = hipatterns.gen_highlighter.hex_color(),
},
}
local minidiff = require "mini.diff"
minidiff.setup {
view = {
style = "sign",
signs = { add = "+", change = "~", delete = "-" },
},
}
local miniclue = require "mini.clue"
miniclue.setup {
triggers = {
{ mode = "n", keys = "<Leader>" },
{ mode = "x", keys = "<Leader>" },
{ mode = "i", keys = "<C-x>" },
{ mode = "n", keys = "g" },
{ mode = "x", keys = "g" },
{ mode = "n", keys = "'" },
{ mode = "n", keys = "`" },
{ mode = "x", keys = "'" },
{ mode = "x", keys = "`" },
{ mode = "n", keys = '"' },
{ mode = "x", keys = '"' },
{ mode = "i", keys = "<C-r>" },
{ mode = "c", keys = "<C-r>" },
{ mode = "n", keys = "<C-w>" },
{ mode = "n", keys = "z" },
{ mode = "x", keys = "z" },
},
clues = {
miniclue.gen_clues.builtin_completion(),
miniclue.gen_clues.g(),
miniclue.gen_clues.marks(),
miniclue.gen_clues.registers(),
miniclue.gen_clues.windows(),
miniclue.gen_clues.z(),
},
window = {
config = { width = "auto", anchor = "SE", row = "auto", col = "auto" },
},
}
end,
},
-- telescope
{
"nvim-telescope/telescope.nvim",
event = "VimEnter",
branch = "0.1.x",
dependencies = {
{ "nvim-lua/plenary.nvim" },
{ "nvim-telescope/telescope-ui-select.nvim" },
},
},
-- scroll bar
-- {
-- "dstein64/nvim-scrollview",
-- },
-- {
-- "ray-x/navigator.lua",
-- dependencies = {
-- "ray-x/guihua.lua",
-- },
-- config = function()
-- require("navigator").setup {}
-- end,
-- },
-- crates support
{
"saecki/crates.nvim",
config = function()
require("crates").setup {}
end,
},
-- hurl support
{
"jellydn/hurl.nvim",
dependencies = {
"MunifTanjim/nui.nvim",
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter",
},
ft = "hurl",
opts = {
debug = false,
show_notification = false,
mode = "split",
formatters = {
json = { "jq" },
},
mappings = {
close = "q",
next_panel = "<C-n>",
prev_panel = "<C-p>",
},
},
keys = {
{ "<leader>A", "<cmd>HurlRunner<CR>", desc = "[HURL] Run All requests" },
{ "<leader>a", "<cmd>HurlRunnerAt<CR>", desc = "[HURL] Run Api request" },
{ "<leader>te", "<cmd>HurlRunnerToEntry<CR>", desc = "[HURL] Run Api request to entry" },
{ "<leader>tE", "<cmd>HurlRunnerToEnd<CR>", desc = "[HURL] un Api request from current entry to end" },
{ "<leader>tm", "<cmd>HurlToggleMode<CR>", desc = "[HURL] Hurl Toggle Mode" },
{ "<leader>tv", "<cmd>HurlVerbose<CR>", desc = "[HURL] Run Api in verbose mode" },
{ "<leader>tV", "<cmd>HurlVeryVerbose<CR>", desc = "[HURL] Run Api in very verbose mode" },
{ "<leader>h", ":HurlRunner<CR>", desc = "[HURL] Hurl Runner", mode = "v" },
},
config = function()
require("hurl").setup {
env_file = {
"hurl.env",
},
}
end,
},
-- helm-chart template syntax support
-- {
-- "towolf/vim-helm",
-- },
{
"f-person/git-blame.nvim",
event = "VeryLazy",
opts = {
enabled = false,
message_template = " <author>-<summary>•<date>",
date_format = "%m-%d-%Y %H:%M:%S",
virtual_text_column = 1,
},
},
{
"dgagn/diagflow.nvim",
opts = {
show_borders = true,
},
},
}
-- keymaps
local k = vim.keymap
-- Non-leader ----------
-- Navigation
k.set("n", "<C-k>", "<C-w><C-k>")
k.set("n", "<C-j>", "<C-w><C-j>")
k.set("n", "<C-h>", "<C-w><C-h>")
k.set("n", "<C-l>", "<C-w><C-l>")
k.set("n", "<left>", '<cmd>echo "Use h to move "<CR>')
k.set("n", "<right>", '<cmd>echo "Use l to move "<CR>')
k.set("n", "<up>", '<cmd>echo "Use k to move "<CR>')
k.set("n", "<down>", '<cmd>echo "Use j to move "<CR>')
-- Toggle
k.set("n", "<C-i>", function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
end)
-- Buffer delete
k.set("n", "<C-ESC>", ":bd<CR>")
-- File delete
k.set("n", "<S-Delete>", ":!rm %<CR>:bd!<CR>", { noremap = true, silent = true })
-- toggle term
k.set("n", "<F2>", "<cmd>Lspsaga term_toggle<CR>")
k.set("t", "<F2>", "<cmd>Lspsaga term_toggle<CR>")
-- Copy, Paste, Undo, Redo, Select all, Join lines
k.set("n", "<C-s>", ":write<CR>")
k.set("v", "<C-c>", '"+y', { silent = true })
k.set("n", "<C-v>", '"+p')
k.set("i", "<C-v>", "<C-r>+")
k.set("v", "<C-x>", '"+d')
k.set("n", "<C-z>", "u")
k.set("i", "<C-z>", "<C-o>u")
k.set("n", "<C-y>", "<C-r>")
k.set("i", "<C-y>", "<C-o><C-r>")
k.set("n", "<C-a>", "ggVG", { noremap = true })
k.set("n", "J", "mzJ`z")
-- Leader ----------
k.set("n", "<leader>q", vim.diagnostic.setloclist, { desc = "Quickfix diagnostic list" })
k.set("v", "<leader>si", ":sort i<CR>", { desc = "Sort lines" })
k.set("n", "<leader>tb", ":GitBlameToggle<CR>", { desc = "Toggle blame" })
local t = require "telescope.builtin"
k.set("n", "<leader>sh", t.help_tags, { desc = "Search Help" })
k.set("n", "<leader>sc", t.git_bcommits, { desc = "Search git commits" })
k.set("n", "<leader>sk", t.keymaps, { desc = "Search Keymaps" })
k.set("n", "<leader>sf", t.find_files, { desc = "Search Files" })
k.set("n", "<leader>ss", t.builtin, { desc = "Search Select Telescope" })
k.set("n", "<leader>sw", t.grep_string, { desc = "Search current Word" })
k.set("n", "<leader>sg", t.live_grep, { desc = "Search by Grep" })
k.set("n", "<leader>sd", t.diagnostics, { desc = "Search Diagnostics" })
k.set("n", "<leader>sr", t.resume, { desc = "Search Resume" })
k.set("n", "<leader>s.", t.oldfiles, { desc = 'Search Recent Files ("." for repeat)' })
k.set("n", "<leader><leader>", t.buffers, { desc = "Find existing buffers" })
-- LSP saga
k.set("n", "K", "<cmd>Lspsaga hover_doc<CR>", { desc = "[LSP]Show docs" })
k.set("n", "<leader>lf", "<cmd>Lspsaga finder<CR>", { desc = "[LSP]Show refs" })
k.set("n", "<leader>ca", "<cmd>Lspsaga code_action<CR>", { desc = "[LSP]Code actions" })
k.set("v", "<leader>ca", "<cmd>Lspsaga range_code_action<CR>", { desc = "[LSP]Code actions (range)" })
k.set("n", "<leader>rn", "<cmd>Lspsaga rename<CR>", { desc = "[LSP]Rename" })
k.set("n", "<leader>de", "<cmd>Lspsaga show_line_diagnostics<CR>", { desc = "[LSP]Show diags" })
k.set("n", "gd", "<cmd>Lspsaga goto_definition<CR>", { desc = "[LSP]Go to def" })
k.set("n", "gi", "<cmd>Lspsaga goto_implementation<CR>", { desc = "[LSP]Go to impl" })
local minifiles = require "mini.files"
k.set("n", "<leader>e", function()
minifiles.open(vim.api.nvim_buf_get_name(0))
minifiles.reveal_cwd()
end, { desc = "Open Mini Files" })
k.set("n", "<leader>cf", function()
local dir = vim.fn.expand "%:h"
local filename = vim.fn.input("New buffer: ", dir .. "/")
if filename ~= "" then
vim.cmd("e " .. filename)
end
end, { desc = "New buffer here" })
-- customized default neovim theme for rust
vim.api.nvim_create_autocmd("FileType", {
pattern = "rust",
callback = function()
local hl = function(group, bg, fg, attr)
fg = fg and "guifg=" .. fg or ""
bg = bg and "guibg=" .. bg or ""
attr = attr and "gui=" .. attr or ""
vim.api.nvim_command("highlight " .. group .. " " .. fg .. " " .. bg .. " " .. attr)
end
-- https://github.com/nshern/neovim-default-colorscheme-extras?tab=readme-ov-file#neovim-default-colorscheme-extras
-- local NvimDarkBlue = "#004c63"
-- local NvimDarkCyan = "#007373"
-- local NvimDarkGreen = "#005523"
-- local NvimDarkGrey1 = "#07080D"
-- local NvimDarkGrey2 = "#14161B"
-- local NvimDarkGrey3 = "#2c2e33"
-- local NvimDarkGrey4 = "#4f5258"
-- local NvimDarkMagenta = "#470045"
-- local NvimDarkRed = "#590008"
-- local NvimDarkYellow = "#6b5300"
-- local NvimLightBlue = "#A6DBFF"
-- local NvimLightCyan = "#8cf8f7"
-- local NvimLightGreen = "#b4f6c0"
-- local NvimLightGrey1 = "#EEF1F8"
-- local NvimLightGrey2 = "#E0E2EA"
-- local NvimLightGrey3 = "#C4C6CD"
-- local NvimLightGrey4 = "#9b9ea4"
-- local NvimLightMagenta = "#FFCAFF"
local NvimLightRed = "#FFC0B9"
-- local NvimLightYellow = "#FCE094"
hl("Number", nil, NvimLightRed, nil)
hl("Comment", nil, nil, "italic")
end,
})
k.set("n", "<F3>", function()
if vim.o.background == "dark" then
vim.o.background = "light"
else
vim.o.background = "dark"
end
vim.cmd "redraw"
end, { desc = "Toggle dark and light" })