-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode_config.lua
246 lines (233 loc) · 6.88 KB
/
code_config.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
-- Set up nvim-cmp.
local cmp = require("blink.cmp")
cmp.setup({
keymap = {
preset = "none",
["<C-e>"] = { "show", "show_documentation", "hide_documentation" },
["<Esc>"] = { "cancel", "fallback" },
["<CR>"] = { "accept", "fallback" },
["<C-u>"] = { "scroll_documentation_up", "fallback" },
["<C-d>"] = { "scroll_documentation_down", "fallback" },
["<Tab>"] = { "select_next", "snippet_forward", "fallback" },
["<S-Tab>"] = { "select_prev", "snippet_backward", "fallback" },
},
appearance = {
use_nvim_cmp_as_default = true,
nerd_font_variant = "mono",
},
fuzzy = {
prebuilt_binaries = { download = vim.g.update_blink },
},
completion = {
list = {
selection = {
preselect = function(ctx)
return ctx.mode ~= "cmdline"
and not require("blink.cmp").snippet_active({ direction = 1 })
end,
},
},
documentation = {
auto_show = true,
auto_show_delay_ms = 250,
},
},
cmdline = {
sources = function()
local type = vim.fn.getcmdtype()
if type == "/" or type == "?" then
return { "buffer" }
end
if type == ":" or type == "@" then
return { "cmdline" }
end
return {}
end,
},
sources = {
default = { "lsp", "path", "snippets", "buffer" },
providers = {
lsp = {
min_keyword_length = 1, -- Number of characters to trigger porvider
score_offset = 0, -- Boost/penalize the score of the items
},
path = {
min_keyword_length = 0,
},
snippets = {
min_keyword_length = 1,
score_offset = 5, -- Boost/penalize the score of the items
},
buffer = {
min_keyword_length = 2,
max_items = 5,
},
},
},
}) -- Setup Autocomplete
require("mini.pairs").setup()
require("conform").setup({
formatters_by_ft = {
lua = { "stylua" },
python = { "isort", "ruff_format" },
},
})
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.api.nvim_create_autocmd("FileType", {
pattern = "*",
group = vim.api.nvim_create_augroup("conform-format", { clear = true }),
callback = function(args)
if vim.bo.filetype == "vim" then
-- autocmd FileType vim nnoremap == ggVG=<C-o> for vim_format
vim.keymap.set("n", "==", "ggVG=<C-o>zz", { buffer = args.buf, desc = "vim_format" })
else
vim.keymap.set("n", "==", "<cmd>Format<cr>", { desc = "conform_format" })
end
end,
})
local gitsigns = require("gitsigns")
gitsigns.setup({
signs = {
add = { text = "" }, -- dashed / double line for unstaged
change = { text = "" },
delete = { text = "=", show_count = true },
topdelete = { text = "", show_count = true },
changedelete = { text = "", show_count = true },
untracked = { text = "" },
},
signs_staged = {
add = { text = "┃" },
change = { text = "┃" },
delete = { text = "_", show_count = true },
topdelete = { text = "‾", show_count = true },
changedelete = { text = "~", show_count = true },
untracked = { text = "┆" },
},
count_chars = { "₁", "₂", "₃", "₄", "₅", "₆", "₇", "₈", "₉", ["+"] = "+" },
on_attach = function(bufnr)
local function map(mode, l, r, opts)
opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, l, r, opts)
end
-- navigation
map("n", "]c", function()
if vim.wo.diff then
vim.cmd.normal({ "]c", bang = true })
else
gitsigns.nav_hunk("next")
end
end, { desc = "next_hunk" })
map("n", "[c", function()
if vim.wo.diff then
vim.cmd.normal({ "[c", bang = true })
else
gitsigns.nav_hunk("prev")
end
end, { desc = "prev_hunk" })
map("n", "]C", function()
gitsigns.nav_hunk("last")
end, { desc = "Last Hunk" })
map("n", "[C", function()
gitsigns.nav_hunk("first")
end, { desc = "First Hunk" })
-- Actions
map("n", "<leader>hs", gitsigns.stage_hunk, { desc = "hunk_stage" })
map("n", "<leader>hr", gitsigns.reset_hunk, { desc = "hunk_reset" })
map("n", "<leader>hu", gitsigns.undo_stage_hunk, { desc = "hunk_unstage" })
map("v", "<leader>hs", function()
gitsigns.stage_hunk({ vim.fn.line("."), vim.fn.line("v") })
end, { desc = "hunk_stage" })
map("v", "<leader>hr", function()
gitsigns.reset_hunk({ vim.fn.line("."), vim.fn.line("v") })
end, { desc = "hunk_reset" })
map("v", "<leader>hu", function()
gitsigns.undo_stage_hunk({ vim.fn.line("."), vim.fn.line("v") })
end, { desc = "hunk_unstage" })
map({ "n", "v" }, "<leader>hh", gitsigns.preview_hunk, { desc = "hunk_hover" })
map("n", "<leader>hd", "<cmd>DiffviewFileHistory %<CR>", { desc = "diffview: file_history" })
map("v", "<leader>hd", ":'<,'>DiffviewFileHistory<CR>", { desc = "diffview: hunk_history" })
map("n", "<leader>td", gitsigns.toggle_deleted, { desc = "gitsigns: toggle_deleted" })
-- Text object
map({ "o", "x" }, "gh", ":<C-U>Gitsigns select_hunk<CR>")
end,
})
local hipatterns = require("mini.hipatterns")
hipatterns.setup({
highlighters = {
-- Highlight standalone 'XXX', 'IMP', 'TODO', 'NOTE'
fixme = {
pattern = "%f[%w]()XXX()%f[%W]",
group = "MiniHipatternsFixme",
},
hack = { pattern = "%f[%w]()IMP()%f[%W]", group = "MiniHipatternsHack" },
todo = {
pattern = "%f[%w]()TODO()%f[%W]",
group = "MiniHipatternsTodo",
},
note = {
pattern = "%f[%w]()NOTE()%f[%W]",
group = "MiniHipatternsNote",
},
-- Highlight hex color strings (`#rrggbb`) using that color
hex_color = hipatterns.gen_highlighter.hex_color(),
},
})
require("render-markdown").setup({
file_types = { "markdown", "vimwiki" },
enabled = true,
code = {
sign = false,
width = "block",
right_pad = 1,
},
heading = {
sign = false,
icons = {},
},
bullet = {
left_pad = 0,
right_pad = 1,
},
})
vim.keymap.set("n", "<F5>", "<cmd>RenderMarkdown toggle<cr>", { desc = "Render Markdown" })
vim.keymap.set("n", "<leader>q", function()
require("quicker").toggle({ open_cmd_mods = { split = "botright" } })
end, {
desc = "Toggle quickfix",
})
require("quicker").setup({
opts = {
winfixheight = false,
},
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",
},
},
})