-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmappings.lua
518 lines (479 loc) · 13.8 KB
/
mappings.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
-- add yours here
local map = vim.keymap.set
local command = vim.api.nvim_create_user_command
map("n", "<A-i>", function()
require("kide.term").toggle()
vim.cmd("startinsert")
end, { desc = "toggle term" })
map("t", "<A-i>", require("kide.term").toggle, { desc = "toggle term" })
map("i", "<A-i>", function()
vim.cmd("stopinsert")
require("kide.term").toggle()
end, { desc = "toggle term" })
map("v", "<A-i>", function()
vim.api.nvim_feedkeys("\027", "xt", false)
local text = require("kide.tools").get_visual_selection()
require("kide.term").toggle()
vim.defer_fn(function()
require("kide.term").send_line(text[1])
end, 500)
end, { desc = "toggle term" })
map("n", "<leader>gb", require("gitsigns").blame_line, { desc = "gitsigns blame line" })
map("n", "<ESC>", "<CMD>noh<CR>", { desc = "Clear Highlight" })
map("n", "<up>", "<CMD>res +5<CR>", { desc = "Resize +5" })
map("n", "<down>", "<CMD>res -5<CR>", { desc = "Resize -5" })
map("n", "<S-up>", "<CMD>res -5<CR>", { desc = "Resize -5" })
map("n", "<S-down>", "<CMD>res +5<CR>", { desc = "Resize +5" })
map("n", "<left>", "<CMD>vertical resize+5<CR>", { desc = "Vertical Resize +5" })
map("n", "<right>", "<CMD>vertical resize-5<CR>", { desc = "Vertical Resize -5" })
map("n", "<S-left>", "<CMD>vertical resize-5<CR>", { desc = "Vertical Resize -5" })
map("n", "<S-right>", "<CMD>vertical resize+5<CR>", { desc = "Vertical Resize +5" })
map("n", "<C-h>", "<C-w>h", { desc = "switch window left" })
map("n", "<C-l>", "<C-w>l", { desc = "switch window right" })
map("n", "<C-j>", "<C-w>j", { desc = "switch window down" })
map("n", "<C-k>", "<C-w>k", { desc = "switch window up" })
-- terminal
map("t", "<C-x>", "<C-\\><C-N>", { desc = "terminal escape terminal mode" })
-- dap
map("n", "<F5>", function()
require("dap").continue()
end, {
desc = "Dap continue",
})
map("n", "<F10>", function()
require("dap").step_over()
end, {
desc = "Dap step_over",
})
map("n", "<F11>", function()
require("dap").step_into()
end, {
desc = "Dap step_into",
})
map("n", "<F12>", function()
require("dap").step_out()
end, {
desc = "Dap step_out",
})
map("n", "<leader>db", function()
require("dap").toggle_breakpoint()
end, { desc = "Dap toggle breakpoint" })
map("n", "<leader>dB", function()
require("dap").set_breakpoint(vim.fn.input("Breakpoint condition: "))
end, { desc = "Dap breakpoint condition" })
map("n", "<leader>dl", function()
require("dap").run_last()
end, {
desc = "Dap run last",
})
map("n", "<Leader>lp", function()
require("dap").set_breakpoint(nil, nil, vim.fn.input("Log point message: "))
end, {
desc = "Dap set_breakpoint",
})
map("n", "<Leader>dr", function()
require("dap").repl.open()
end, {
desc = "Dap repl open",
})
map({ "n", "v" }, "<Leader>dh", function()
require("dap.ui.widgets").hover()
end, {
desc = "Dap hover",
})
map({ "n", "v" }, "<Leader>dp", function()
require("dap.ui.widgets").preview()
end, {
desc = "Dap preview",
})
map("n", "<Leader>df", function()
local widgets = require("dap.ui.widgets")
widgets.centered_float(widgets.frames)
end, {
desc = "Dap centered_float frames",
})
map("n", "<Leader>dv", function()
local widgets = require("dap.ui.widgets")
widgets.centered_float(widgets.scopes)
end, {
desc = "Dap centered_float scopes",
})
map("n", "<leader>e", function()
Snacks.explorer.open({})
end, { desc = "files", silent = true, noremap = true })
-- outline
map("n", "<leader>o", "<CMD>Outline<CR>", { desc = "Symbols Outline" })
-- task
command("TaskRun", function()
require("kide.term").input_run(false)
end, { desc = "Task Run" })
command("TaskRunLast", function()
require("kide.term").input_run(true)
end, { desc = "Restart Last Task" })
map("n", "<A-l>", function()
require("conform").format({ lsp_fallback = true })
end, { desc = "format file" })
map("v", "<A-l>", function()
vim.api.nvim_feedkeys("\027", "xt", false)
local start_pos = vim.api.nvim_buf_get_mark(0, "<")
local end_pos = vim.api.nvim_buf_get_mark(0, ">")
require("conform").format({
range = {
start = start_pos,
["end"] = end_pos,
},
lsp_fallback = true,
})
end, { desc = "format range", silent = true, noremap = true })
-- Git
map("n", "]c", function()
local gs = require("gitsigns")
if vim.wo.diff then
return "]c"
end
vim.schedule(function()
gs.next_hunk()
end)
return "<Ignore>"
end, { expr = true, desc = "Git Next Hunk" })
map("n", "[c", function()
local gs = require("gitsigns")
if vim.wo.diff then
return "[c"
end
vim.schedule(function()
gs.prev_hunk()
end)
return "<Ignore>"
end, { expr = true, desc = "Git Prev Hunk" })
map("n", "[e", function()
vim.diagnostic.jump({ count = -1, severity = vim.diagnostic.severity.ERROR, float = true })
end, { desc = "Jump to the previous diagnostic error" })
map("n", "]e", function()
vim.diagnostic.jump({ count = 1, severity = vim.diagnostic.severity.ERROR, float = true })
end, { desc = "Jump to the next diagnostic error" })
map("n", "go", vim.diagnostic.open_float, { desc = "Open float Diagnostics" })
-- quickfix next/prev
-- map("n", "]q", "<CMD>cnext<CR>", { desc = "Quickfix Next" })
-- map("n", "[q", "<CMD>cprev<CR>", { desc = "Quickfix Prev" })
-- local list next/prev
-- map("n", "]l", "<CMD>lnext<CR>", { desc = "Location List Next" })
-- map("n", "[l", "<CMD>lprev<CR>", { desc = "Location List Prev" })
command("InlayHint", function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({}))
end, { desc = "LSP Inlay Hint" })
command("CodeLens", function()
vim.lsp.codelens.refresh()
end, { desc = "LSP CodeLens" })
command("CodeLensClear", function()
vim.lsp.codelens.clear()
end, { desc = "LSP CodeLens" })
local function _on_list()
local templist = {}
local tempctx = {}
return function(ctx)
vim.list_extend(templist, ctx.items)
tempctx = vim.tbl_extend("keep", tempctx, ctx)
tempctx.items = templist
vim.fn.setqflist({}, " ", tempctx)
vim.cmd("botright copen")
end
end
command("LspDocumentSymbols", function(_)
vim.lsp.buf.document_symbol({
on_list = _on_list(),
})
end, {
desc = "Lsp Document Symbols",
nargs = 0,
range = true,
})
command("LspWorkspaceSymbols", function(opts)
if opts.range > 0 then
local text = require("kide.tools").get_visual_selection()
vim.lsp.buf.workspace_symbol(text[1], { on_list = _on_list() })
else
vim.lsp.buf.workspace_symbol(opts.args, { on_list = _on_list() })
end
end, {
desc = "Lsp Workspace Symbols",
nargs = "?",
range = true,
})
local severity_key = {
"ERROR",
"WARN",
"INFO",
"HINT",
}
command("DiagnosticsWorkspace", function(opts)
local level = opts.args
if level == nil or level == "" then
vim.diagnostic.setqflist()
else
vim.diagnostic.setqflist({ severity = level })
end
end, {
desc = "Diagnostics Workspace",
nargs = "?",
complete = function(al, _, _)
return vim.tbl_filter(function(item)
return vim.startswith(item, al)
end, severity_key)
end,
})
command("DiagnosticsDocument", function(opts)
local level = opts.args
if level == nil or level == "" then
vim.diagnostic.setloclist()
else
vim.diagnostic.setloclist({ severity = level })
end
end, {
desc = "Diagnostics Document",
nargs = "?",
complete = function(al, _, _)
return vim.tbl_filter(function(item)
return vim.startswith(item, al)
end, severity_key)
end,
})
command("Bn", function()
require("nvchad.tabufline").next()
end, { desc = "buffer goto next" })
command("Bp", function()
require("nvchad.tabufline").prev()
end, { desc = "buffer goto prev" })
-- find files
if vim.fn.executable("fd") == 1 then
command("Fd", function(opt)
vim.fn.setqflist({}, " ", { lines = vim.fn.systemlist("fd --type file " .. opt.args), efm = "%f" })
vim.cmd("botright copen")
end, {
desc = "find files",
nargs = "?",
})
end
if vim.fn.executable("find") == 1 then
command("Find", function(opt)
vim.fn.setqflist({}, " ", { lines = vim.fn.systemlist("find . -type f -iname '" .. opt.args .. "'"), efm = "%f" })
vim.cmd("botright copen")
end, {
desc = "find files",
nargs = 1,
})
end
command("CloseOtherBufs", function(_)
local bufs = vim.api.nvim_list_bufs()
local cur = vim.api.nvim_get_current_buf()
for _, v in ipairs(bufs) do
if vim.bo[v].buflisted and cur ~= v then
local ok = pcall(vim.api.nvim_buf_delete, v, { force = false, unload = false })
if not ok then
vim.cmd("b " .. v)
return
end
end
end
end, {
desc = "find files",
nargs = 0,
})
map("n", "<leader>fq", function()
Snacks.picker.qflist()
end, { desc = "Quickfix" })
map("n", "<leader>fb", function()
Snacks.picker.buffers()
end, { desc = "Find buffer" })
map("n", "<leader>ff", function()
Snacks.picker.files()
end, { desc = "Find files" })
map("n", "<leader>fd", function()
Snacks.picker.diagnostics()
end, { desc = "Find diagnostics" })
map("v", "<leader>ff", function()
vim.api.nvim_feedkeys("\027", "xt", false)
local text = require("kide.tools").get_visual_selection()
local param = text[1]
Snacks.picker.files({ args = { param } })
end, { desc = "find files", silent = true, noremap = true })
map("v", "<leader>fw", function()
vim.api.nvim_feedkeys("\027", "xt", false)
local text = require("kide.tools").get_visual_selection()
local param = text[1]
Snacks.picker.grep({ search = param })
end, { desc = "live grep", silent = true, noremap = true })
map("n", "<leader>fw", function()
Snacks.picker.grep()
end, { desc = "live grep", silent = true, noremap = true })
if vim.base64 then
command("Base64Encode", function(opt)
local text
if opt.range > 0 then
text = require("kide.tools").get_visual_selection()
text = table.concat(text, "\n")
else
text = opt.args
end
vim.notify(vim.base64.encode(text), vim.log.levels.INFO)
end, {
desc = "base64 encode",
nargs = "?",
range = true,
})
command("Base64Decode", function(opt)
local text
if opt.range > 0 then
text = require("kide.tools").get_visual_selection()
text = table.concat(text, "\n")
else
text = opt.args
end
text = require("kide.tools").base64_url_safe_to_std(text)
vim.notify(vim.base64.decode(text), vim.log.levels.INFO)
end, {
desc = "base64 decode",
nargs = "?",
range = true,
})
end
local function creat_trans_command(name, from, to)
command(name, function(opt)
local text
if opt.range > 0 then
text = require("kide.tools").get_visual_selection()
text = table.concat(text, "\n")
else
text = opt.args
end
require("kide.gpt.translate").translate_float({ text = text, from = from, to = to })
end, {
desc = "translate",
nargs = "?",
range = true,
})
end
creat_trans_command("TransAutoZh", "auto", "中文")
map("v", "<leader>tc", function()
vim.api.nvim_feedkeys("\027", "xt", false)
local text = require("kide.tools").get_visual_selection()
require("kide.gpt.translate").translate_float({ text = table.concat(text, "\n"), from = "auto", to = "中文" })
end, {})
creat_trans_command("TransEnZh", "英语", "中文")
creat_trans_command("TransZhEn", "中文", "英语")
creat_trans_command("TransIdZh", "印尼语", "中文")
command("Gpt", function(opt)
local q
local code
if opt.range > 0 then
code = require("kide.tools").get_visual_selection()
end
if opt.args and opt.args ~= "" then
q = opt.args
end
require("kide.gpt.chat").toggle_gpt({
code = code,
question = q,
})
end, {
desc = "Gpt",
nargs = "*",
range = true,
})
map("n", "<A-k>", require("kide.gpt.chat").toggle_gpt, { desc = "Gpt" })
map("i", "<A-k>", require("kide.gpt.chat").toggle_gpt, { desc = "Gpt" })
map("v", "<A-k>", function()
vim.api.nvim_feedkeys("\027", "xt", false)
local text = require("kide.tools").get_visual_selection()
require("kide.gpt.chat").toggle_gpt({
code = text,
})
end, { desc = "Gpt" })
command("GptLast", function(opt)
require("kide.gpt.chat").toggle_gpt({
last = true,
})
end, {
desc = "Gpt",
nargs = "*",
range = true,
})
command("GptReasoner", function(opt)
local q
local code
if opt.range > 0 then
code = require("kide.tools").get_visual_selection()
end
if opt.args and opt.args ~= "" then
q = opt.args
end
require("kide.gpt.chat").toggle_gpt({
reasoner = true,
code = code,
question = q,
})
end, {
desc = "Gpt",
nargs = "*",
range = true,
})
command("LspInfo", function(_)
require("kide.lspui").open_info()
end, {
desc = "Lsp info",
nargs = 0,
range = false,
})
command("NotificationHistory", function(_)
Snacks.notifier.show_history()
end, {
desc = "Notification History",
nargs = 0,
range = false,
})
command("LspLog", function(_)
vim.cmd("tabedit " .. vim.lsp.log.get_filename())
vim.cmd("normal! G")
end, {
desc = "Lsp log",
nargs = 0,
range = false,
})
command("Go", function(opt)
local cmd = { "go" }
if opt.args and opt.args ~= "" then
vim.list_extend(cmd, vim.split(opt.args, " "))
end
require("kide.term").toggle(cmd)
end, {
desc = "Go cmd",
nargs = "*",
range = false,
complete = "file",
})
command("ImageHover", function()
Snacks.image.hover()
end, {
desc = "Image Hover",
nargs = 0,
range = false,
})
if vim.fn.executable("cargo-owlsp") == 1 then
map("n", "<A-o>", require("kide.lsp.rustowl").rustowl_cursor, { noremap = true, silent = true })
end
map({ "n", "i" }, "<A-h>", function()
local codecompanion = require("codecompanion")
codecompanion.chat({ fargs = { "toggle" } })
end, { desc = "CodeCompanion chat" })
map({ "n", "i" }, "<A-r>", function()
local codecompanion = require("codecompanion")
codecompanion.chat()
end, { desc = "CodeCompanion chat" })
map({ "v" }, "<A-e>", "<CMD>CodeCompanion /explain<CR>", { desc = "CodeCompanion explain" })
require("kide.tools").setup()
require("kide.tools.maven").setup()
require("kide.tools.plantuml").setup()
require("kide.tools.mermaid").setup()
require("kide.tools.curl").setup()
require("kide.gpt.commit").setup()
require("kide.gpt.code").setup()