nix/homes/modules/programs/neovim/init.lua
2026-03-19 12:24:19 +00:00

95 lines
2.3 KiB
Lua

vim.g.mapleader = " "
vim.opt.termguicolors = true -- use terminal colors
vim.opt.relativenumber = true
vim.opt.number = true
vim.opt.wrap = false
vim.opt.colorcolumn = "80"
vim.opt.scrolloff = 4
require("plugins")
require("lsp")
require("colors")
-- move windows :3
vim.keymap.set("n", "<A-h>", function()
vim.cmd("wincmd h")
end)
vim.keymap.set("n", "<A-j>", function()
vim.cmd("wincmd j")
end)
vim.keymap.set("n", "<A-k>", function()
vim.cmd("wincmd k")
end)
vim.keymap.set("n", "<A-l>", function()
vim.cmd("wincmd l")
end)
-- splits <3 (i love splits sm)
vim.keymap.set("n", "<leader>s", function()
vim.cmd("split")
end)
vim.keymap.set("n", "<leader>v", function()
vim.cmd("vsplit")
end)
-- u can put delta inside of neovim omg they are spoiling me <3
local git_diff_win = nil
vim.api.nvim_create_autocmd("VimResized", {
callback = function()
if git_diff_win and vim.api.nvim_win_is_valid(git_diff_win) then
local width = math.floor(vim.o.columns * 0.9)
local height = math.floor((vim.o.lines - 2) * 0.9)
vim.api.nvim_win_set_config(git_diff_win, {
relative = "editor",
width = width,
height = height,
col = math.floor((vim.o.columns - width) / 2),
row = math.floor((vim.o.lines - height) / 2) - 2,
})
end
end,
})
vim.keymap.set("n", "<leader>gd", function()
if git_diff_win and vim.api.nvim_win_is_valid(git_diff_win) then
vim.api.nvim_win_close(git_diff_win, true)
git_diff_win = nil
return
end
local buf = vim.api.nvim_create_buf(false, true)
vim.bo[buf].filetype = "terminal"
-- deletes the last two lines of the buffer when the process exits :3
vim.api.nvim_create_autocmd("TermClose", {
buffer = buf,
callback = function()
vim.defer_fn(function()
vim.bo[buf].modifiable = true
vim.api.nvim_buf_set_lines(buf, -3, -1, false, {})
vim.bo[buf].modifiable = false
end, 10)
end,
})
local width = math.floor(vim.o.columns * 0.9)
local height = math.floor((vim.o.lines - 2) * 0.9)
git_diff_win = vim.api.nvim_open_win(buf, true, {
relative = "editor",
width = width,
height = height,
col = math.floor((vim.o.columns - width) / 2),
row = math.floor((vim.o.lines - height) / 2) - 2,
style = "minimal",
border = "rounded",
})
vim.fn.jobstart("git diff | delta --pager=never", { term = true })
vim.keymap.set("n", "q", "<cmd>close<CR>", { buffer = buf })
end)