-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
415 lines (371 loc) · 15.9 KB
/
init.lua
File metadata and controls
415 lines (371 loc) · 15.9 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
vim.o.number = true
vim.o.relativenumber = true
vim.o.wrap = false
vim.o.tabstop = 4
vim.o.shiftwidth = 4
vim.opt.softtabstop = 0
vim.opt.expandtab = true
vim.o.signcolumn = "yes"
vim.o.swapfile = false
-- vim.opt.cursorline = true
vim.g.mapleader = " "
vim.o.winborder = "rounded"
vim.opt.background = "dark"
-- vim.opt.background = "light"
vim.opt.termguicolors = true
-- vim.opt.guicursor = "i-c:block-Cursor"
vim.opt.iskeyword:remove("_")
vim.opt.ignorecase = true
vim.opt.smartcase = true
vim.opt.langmap = table.concat({
"фa,иb,сc,вd,уe,аf,пg,рh,шi,оj,лk,дl,ьm,тn,щo,зp,йq,кr,ыs,еt,гu,мv,цw,чx,нy,яz",
"ФA,ИB,СC,ВD,УE,АF,ПG,РH,ШI,ОJ,ЛK,ДL,ЬM,ТN,ЩO,ЗP,ЙQ,КR,ЫS,ЕT,ГU,МV,ЦW,ЧX,НY,ЯZ"
}, ",")
vim.keymap.set({ 'n', 'v', 'x' }, '<leader>y', '"+y<CR>')
vim.keymap.set({ 'n', 'v', 'x' }, '<leader>yy', '"+yy<CR>')
vim.keymap.set({ 'n', 'v', 'x' }, '<leader>P', '"+P<CR>')
vim.keymap.set({ 'n', 'v', 'x' }, '<leader>p', '"+p<CR>')
vim.keymap.set({ 'n', 'v', 'x' }, '<M-l>', 'zl')
vim.keymap.set({ 'n', 'v', 'x' }, '<M-h>', 'zh')
vim.keymap.set({ 'n', 'v', 'x' }, '<M-L>', 'zL')
vim.keymap.set({ 'n', 'v', 'x' }, '<M-H>', 'zH')
vim.keymap.set({ 'n', 'v', 'x' }, '<M-j>', '<C-e>')
vim.keymap.set({ 'n', 'v', 'x' }, '<M-k>', '<C-y>')
vim.keymap.set({ 'n', 'v', 'x' }, '<leader>x', ':e ~/buffer.md<CR>')
vim.keymap.set({ 'n', 'v', 'x' }, '<leader>c', ':e ~/Notes/scratchpad.md<CR>')
vim.keymap.set({ 'n', 'v', 'x' }, '<C-c>at', ':e ~/org/todo.org<CR>')
vim.keymap.set({ "i", "c" }, "<C-a>", "<Left>", { noremap = true })
vim.keymap.set({ "i", "c" }, "<C-k>", "<Right>", { noremap = true })
vim.keymap.set({ "i", "c" }, "<C-d>", "<delete>", { noremap = true })
vim.keymap.set({ "i", "c" }, "<D-Space>", "", { noremap = true })
vim.keymap.set("c", "<C-n>", "<Down>")
vim.keymap.set("c", "<C-p>", "<Up>")
vim.keymap.set("i", "<C-S-v>", "<C-r>+", { noremap = true, silent = true })
vim.keymap.set('n', '<leader><CR>', ":noh<CR>")
vim.keymap.set('n', '<leader>q', "@q")
vim.keymap.set('n', '<leader>lf', vim.lsp.buf.format)
for i = 1, 9 do
vim.keymap.set("n", "<Leader>" .. i, i .. "gt", opts)
end
vim.keymap.set("n", "<Leader>t-", ":-tabm<CR>", opts)
vim.keymap.set("n", "<Leader>t=", ":+tabm<CR>", opts)
vim.keymap.set("n", "<Leader>tn", ':tabedit <C-r>=escape(expand("%:p:h"), " ")<cr>/', opts)
vim.keymap.set("n", "<Leader>t0", ":tabo ", opts)
vim.keymap.set("n", "<Leader>tc", ":tabclose<CR>", opts)
vim.keymap.set("n", "<Leader>te", ":tab terminal<CR>", opts)
vim.keymap.set('t', '<C-Space>', [[<C-\><C-n>]], { noremap = true })
vim.keymap.set("n", "<leader>o", ":Open %<CR>", { noremap = true })
vim.keymap.set("n", "<M-c>", function()
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
local line = vim.api.nvim_get_current_line()
-- find word boundaries
local s, e = line:find("[%w_]+", col + 1)
if not s then return end
local word = line:sub(s, e)
local cap = word:sub(1,1):upper() .. word:sub(2):lower()
vim.api.nvim_set_current_line(
line:sub(1, s - 1) .. cap .. line:sub(e + 1)
)
-- optional cursor placement
vim.api.nvim_win_set_cursor(0, { row, e })
end, { noremap = true, desc = "Capitalize word (pure Lua)" })
vim.keymap.set("n", "<leader>v", ":vsplit<CR>", { noremap = true })
vim.keymap.set("n", "<leader>h", ":split<CR>", { noremap = true })
vim.keymap.set("n", "<M-w>", "<C-w><C-w>", { noremap = true })
vim.pack.add({
-- { src = "https://github.com/stevearc/oil.nvim" },
{ src = "https://github.com/echasnovski/mini.pick" },
{ src = "https://github.com/nvim-treesitter/nvim-treesitter" },
{ src = "https://github.com/neovim/nvim-lspconfig" },
{ src = "https://github.com/windwp/nvim-autopairs" },
{ src = "https://github.com/nvim-mini/mini.ai" },
{ src = "https://github.com/brenton-leighton/multiple-cursors.nvim" },
{ src = "https://github.com/WTFox/jellybeans.nvim" },
{ src = "https://github.com/thembones79/mine-pine" },
{ src = "https://github.com/rose-pine/neovim" },
{ src = "https://github.com/ramojus/mellifluous.nvim" },
{ src = "https://github.com/blazkowolf/gruber-darker.nvim" },
{ src = "https://github.com/thesimonho/kanagawa-paper.nvim"},
{ src = "https://github.com/rebelot/kanagawa.nvim" },
{ src = "https://github.com/Shatur/neovim-ayu" },
{ src = "https://github.com/tanvirtin/monokai.nvim" },
-- { src = "https://github.com/github/copilot.vim" },
{ src = "https://github.com/supermaven-inc/supermaven-nvim" },
{ src = "https://github.com/xero/miasma.nvim" },
})
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if client:supports_method('textDocument/completion') then
vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true })
end
end,
})
-- Define the filetypes where you want wrapping + visual movement
local wrap_filetypes = { "markdown", "typst", "tex" }
-- Create an autocmd group to avoid duplicates
vim.api.nvim_create_augroup("WrapAndVisualMove", { clear = true })
vim.api.nvim_create_autocmd("FileType", {
group = "WrapAndVisualMove",
pattern = wrap_filetypes,
callback = function()
-- Enable wrapping and linebreak
vim.opt_local.wrap = true
vim.opt_local.linebreak = true
-- Remap movement keys to move by display lines, not logical lines
local opts = { noremap = true, silent = true, buffer = true }
vim.keymap.set({ 'n', 'v', 'x' }, "j", "gj", opts)
vim.keymap.set({ 'n', 'v', 'x' }, "о", "gj", opts)
vim.keymap.set({ 'n', 'v', 'x' }, "<C-n>", "gj")
vim.keymap.set({ 'n', 'v', 'x' }, "k", "gk", opts)
vim.keymap.set({ 'n', 'v', 'x' }, "л", "gk", opts)
vim.keymap.set({ 'n', 'v', 'x' }, "<Down>", "gj", opts)
vim.keymap.set({ 'n', 'v', 'x' }, "<Up>", "gk", opts)
end,
})
-- Disable line numbers for specific text-like formats (but not .txt)
vim.api.nvim_create_autocmd("FileType", {
pattern = { "markdown", },
callback = function()
vim.opt_local.number = false
vim.opt_local.relativenumber = false
end,
})
vim.cmd("set completeopt+=noselect")
require "mini.pick".setup()
require "mini.ai".setup()
require "multiple-cursors".setup()
-- require "copilot.vim".setup()
require("supermaven-nvim").setup({
keymaps = {
accept_suggestion = "<Tab>",
clear_suggestion = "<C-]>",
},
-- ignore_filetypes = { cpp = true }, -- or { "cpp", }
color = {
suggestion_color = "#ffffff",
cterm = 244,
},
log_level = "info", -- set to "off" to disable logging completely
disable_inline_completion = false, -- disables inline completion for use with cmp
disable_keymaps = false, -- disables built in keymaps for more manual control
condition = function()
return false
end -- condition to check for stopping supermaven, `true` means to stop supermaven when the condition is true.
})
-- require "oil".setup()
-- require "nvim-autopairs".setup()
require "nvim-treesitter.configs".setup({
ensure_installed = { "typescript", "javascript", "zig", "c", "python", "cpp", "kotlin", "typst", "dart", "go" },
highlight = { enable = true }
})
vim.lsp.config.dartls = {
cmd = { "dart", "language-server", "--protocol=lsp" },
filetypes = { "dart" },
root_markers = { "pubspec.yaml" },
}
vim.lsp.enable({ "lua_ls", "zls", "clangd", "typescript-language-server", "tailwindcss-language-server",
"prisma-language-server", "kotlin-language-server", "marksman", "tinymist", "pyright", "asm-lsp", "dartls", "gopls" })
-- vim.cmd("colorscheme jellybeans-mono")
-- vim.cmd("colorscheme jellybeans-default")
-- vim.cmd("colorscheme jellybeans")
-- vim.cmd("colorscheme rose-pine")
-- vim.cmd("colorscheme mine-pine-moon")
-- vim.cmd("colorscheme mine-pine-prime")
-- vim.cmd("colorscheme mellifluous")
-- vim.cmd("colorscheme desert")
-- vim.cmd("colorscheme retrobox")
-- vim.cmd("colorscheme habamax")
-- vim.cmd("colorscheme peachpuff")
-- vim.cmd("colorscheme slate")
-- vim.cmd("colorscheme quiet")
vim.cmd("colorscheme gruber-darker")
-- vim.cmd("colorscheme kanagawa-paper")
-- vim.cmd("colorscheme kanagawa")
-- vim.cmd("colorscheme kanagawa-lotus")
-- vim.cmd("colorscheme ayu")
-- vim.cmd("colorscheme monokai")
-- vim.cmd("colorscheme monokai_ristretto")
-- vim.cmd("colorscheme miasma")
-- vim.cmd("colorscheme blue")
vim.keymap.set("n", "<leader>ff", ':Pick files<CR>')
vim.keymap.set("n", "<leader>fg", ':Pick grep_live<CR>')
vim.keymap.set("n", "<leader>fb", ':Pick buffers<CR>')
vim.keymap.set('n', '<leader>e', ":Explore<CR>")
-- vim.keymap.set('n', '<leader>e', ":Oil<CR>")
vim.keymap.set('n', 'gl', vim.diagnostic.open_float, { desc = "Show diagnostics (float)" })
-- vim.keymap.set("n", "<leader>sc", function()
-- require("stay-centered").toggle()
-- end, { desc = "Toggle Stay Centered" })
-- Remaps for multiple cursors
-- Add cursor down
vim.keymap.set({ "n", "x" }, "<C-j>", "<Cmd>MultipleCursorsAddDown<CR>", { desc = "Add a cursor then move down" })
vim.keymap.set({ "n", "i", "x" }, "<C-Down>", "<Cmd>MultipleCursorsAddDown<CR>", { desc = "Add a cursor then move down" })
-- Add cursor up
vim.keymap.set({ "n", "x" }, "<C-k>", "<Cmd>MultipleCursorsAddUp<CR>", { desc = "Add a cursor then move up" })
vim.keymap.set({ "n", "i", "x" }, "<C-Up>", "<Cmd>MultipleCursorsAddUp<CR>", { desc = "Add a cursor then move up" }) -- Mouse add / delete cursor
vim.keymap.set({ "n", "i" }, "<C-LeftMouse>", "<Cmd>MultipleCursorsMouseAddDelete<CR>", { desc = "Add or remove a cursor" })
-- Add cursors to all matches
vim.keymap.set({ "n", "x" }, "<Leader>a", "<Cmd>MultipleCursorsAddMatches<CR>", { desc = "Add cursors to the word under the cursor" })
vim.keymap.set({ "n", "x" }, "<M-n>", "<Cmd>MultipleCursorsAddJumpNextMatch<CR>")
vim.keymap.set({ "n", "x" }, "<M-N>", "<Cmd>MultipleCursorsAddJumpPrevMatch<CR>")
vim.keymap.set({ "n", "x" }, "<leader>l", function() require("multiple-cursors").align() end)
-- Make background transparent
-- vim.api.nvim_set_hl(0, "Normal", { bg = "none" })
-- vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" })
-- vim.api.nvim_set_hl(0, "SignColumn", { bg = "none" })
-- vim.api.nvim_set_hl(0, "LineNr", { bg = "none" })
-- vim.api.nvim_set_hl(0, "CursorLineNr", { bg = "none" })
-- vim.api.nvim_set_hl(0, "CursorLine", { bg = "none" })
vim.keymap.set("n", "<leader>ts", function()
if vim.o.laststatus == 0 then
vim.o.laststatus = 1
vim.o.showtabline = 1
vim.o.cmdheight = 1
else
vim.o.laststatus = 0
vim.o.showtabline = 0
vim.o.cmdheight = 0
end
end, { desc = "Toggle statusline" })
vim.keymap.set("n", "<leader>r", function()
local file = vim.fn.expand("%:p") -- absolute path to current file
local ext = vim.fn.expand("%:e") -- file extension
local dir = vim.fn.expand("%:p:h") -- directory of current file
local filename = vim.fn.expand("%:t:r") -- name without extension
-- Function to properly quote/escape paths for shell commands
local function shell_escape(str)
return "'" .. str:gsub("'", "'\"'\"'") .. "'"
end
local function spawn_wezterm(command, title)
title = title or ("Running " .. filename)
return string.format(
"wezterm cli spawn --new-window --cwd %s bash -c %s",
shell_escape(dir),
shell_escape("echo 'Window: " .. title .. "' && " .. command .. "; echo 'Process finished. Press Enter to close...'; read")
)
end
-- Check if file is saved
if vim.bo.modified then
print("File has unsaved changes. Save first!")
return
end
local cmd = nil
if ext == "c" then
local exe_path = dir .. "/" .. filename
-- Add debug flags and better error handling
local compile_cmd = string.format("gcc -Wall -Wextra -g %s -o %s",
shell_escape(file),
shell_escape(exe_path)
)
cmd = string.format("%s && %s",
compile_cmd,
spawn_wezterm("./" .. filename, "C Program: " .. filename)
)
elseif ext == "cpp" then
local exe_path = dir .. "/" .. filename
-- Add C++17 standard and debug flags
local compile_cmd = string.format("g++ -Wall -Wextra -std=c++17 -g %s -o %s",
shell_escape(file),
shell_escape(exe_path)
)
cmd = string.format("%s && %s",
compile_cmd,
spawn_wezterm("./" .. filename, "C++ Program: " .. filename)
)
elseif ext == "py" then
cmd = spawn_wezterm("python3 " .. shell_escape(file), "Python: " .. filename)
elseif ext == "lua" then
cmd = spawn_wezterm("lua " .. shell_escape(file), "Lua: " .. filename)
elseif ext == "typ" then
local pdf_path = dir .. "/" .. filename .. ".pdf"
-- Just run typst watch - it will compile initially and then watch for changes
local typst_cmd = string.format(
"echo 'Starting Typst watch mode...' && typst watch %s",
shell_escape(file)
)
cmd = string.format(
"%s & sleep 1 && zathura %s > /dev/null 2>&1 &",
spawn_wezterm(typst_cmd, "Typst Watch: " .. filename),
shell_escape(pdf_path)
)
elseif ext == "rs" then
-- Rust support
cmd = spawn_wezterm("cargo run", "Rust: " .. filename)
elseif ext == "go" then
-- Go support
cmd = spawn_wezterm("go run " .. shell_escape(file), "Go: " .. filename)
elseif ext == "js" then
-- JavaScript/Node.js support
cmd = spawn_wezterm("node " .. shell_escape(file), "Node.js: " .. filename)
elseif ext == "java" then
-- Java support
local class_name = filename
local compile_and_run = string.format(
"javac %s && java -cp %s %s",
shell_escape(file),
shell_escape(dir),
class_name
)
cmd = spawn_wezterm(compile_and_run, "Java: " .. filename)
elseif ext == "sh" or ext == "bash" then
-- Shell script support
cmd = spawn_wezterm("chmod +x " .. shell_escape(file) .. " && " .. shell_escape(file), "Shell: " .. filename)
elseif ext == "zig" then
-- Zig support
cmd = spawn_wezterm("zig run " .. shell_escape(file), "Zig: " .. filename)
elseif ext == "kt" then
-- Kotlin (.kt) support: compile to jar with runtime and run with java
local jar_path = dir .. "/" .. filename .. ".jar"
local compile_cmd = string.format(
"kotlinc %s -include-runtime -d %s",
shell_escape(file),
shell_escape(jar_path)
)
local run_cmd = string.format("java -jar %s", shell_escape(jar_path))
cmd = string.format("%s && %s", compile_cmd, spawn_wezterm(run_cmd, "Kotlin: " .. filename))
elseif ext == "kts" then
-- Kotlin script (.kts) support: run directly with kotlin
cmd = spawn_wezterm("kotlin " .. shell_escape(file), "Kotlin Script: " .. filename)
else
print("Unsupported file type: " .. ext)
print("Supported: c, cpp, py, lua, typ, rs, go, js, java, sh, bash, zig, kt, kts")
return
end
print("Running: " .. filename .. "." .. ext)
vim.cmd("!" .. cmd)
end, {
desc = "Compile/Run various languages in new WezTerm window",
noremap = true,
silent = true,
})
-- Additional keymap for killing running processes
vim.keymap.set("n", "<leader>rk", function()
vim.cmd("!pkill -f 'typst watch'") -- Kill typst watch processes
vim.cmd("!pkill zathura") -- Kill zathura instances
print("Killed running processes (typst watch, zathura)")
end, {
desc = "Kill running processes (typst watch, zathura)",
noremap = true,
silent = true,
})
if vim.g.neovide then
vim.o.guifont = "Iosevka Fixed"
-- vim.o.guifont = "Consolas"
-- vim.o.guifont = "Cascadia Mono"
-- vim.o.guifont = "Fira Mono"
-- vim.o.guifont = "Input Mono"
-- vim.o.guifont = "Source Code Pro"
-- vim.o.guifont = "ComicShannsMono Nerd Font"
vim.g.neovide_scale_factor = 2.5
vim.g.neovide_cursor_trail_size = 2.0
vim.g.neovide_cursor_antialiasing = true
vim.g.neovide_cursor_unfocused_outline_width = 0.200
local change_scale = function(delta)
vim.g.neovide_scale_factor = vim.g.neovide_scale_factor + delta
end
vim.keymap.set({ 'n', 'v', 'x', 't' }, "<C-=>", function() change_scale(0.3) end, { desc = "Zoom in" })
vim.keymap.set({ 'n', 'v', 'x', 't' }, "<C-->", function() change_scale(-0.3) end, { desc = "Zoom out" })
vim.keymap.set({ 'n', 'v', 'x', 't' }, "<C-0>", function() vim.g.neovide_scale_factor = 2.5 end,
{ desc = "Reset zoom" })
end