less of a rewrite, more of a restructure

This commit is contained in:
2026-04-07 14:06:49 +01:00
parent 7eae05c8e2
commit cfc5baa8ad
26 changed files with 406 additions and 456 deletions

117
init.lua
View File

@@ -1,10 +1,8 @@
-- Set mapleader
vim.g.mapleader = "<Space>"
vim.g.maplocalleader = ","
-- Lazy
require("config.lazy")
-- Colorcheme
vim.cmd.colorscheme("catppuccin-mocha")
-- Line numbers
vim.opt.cursorline = true
vim.wo.relativenumber = true
@@ -12,22 +10,6 @@ vim.wo.number = true
vim.api.nvim_set_hl(0, "LineNr", { fg = "#6c7086" }) -- overlay0
vim.api.nvim_set_hl(0, "CursorLineNr", { fg = "#cba6f7", bold = true }) -- mauve
local cursorline_group = vim.api.nvim_create_augroup("CursorLineControl", { clear = true })
vim.api.nvim_create_autocmd({ "WinEnter", "BufEnter" }, {
group = cursorline_group,
callback = function()
vim.opt_local.cursorline = true
end,
})
vim.api.nvim_create_autocmd({ "WinLeave" }, {
group = cursorline_group,
callback = function()
vim.opt_local.cursorline = false
end,
})
-- Windows
vim.opt.splitbelow = true
vim.opt.splitright = true
@@ -52,99 +34,12 @@ vim.opt.incsearch = true
-- Nowrap
vim.opt.wrap = false
-- Colorcheme
vim.cmd.colorscheme("catppuccin-mocha")
-- Scrolloff
vim.opt.scrolloff = math.floor(vim.o.lines / 2) - 3
-- Indent
vim.o.autoindent = true
-- Keymap function
function Keymap(mode, key, binding)
vim.keymap.set(mode, key, binding, { noremap = true, silent = true })
end
-- Better keymaps
Keymap("i", "jj", "<Esc>")
Keymap("n", "q:", ":")
Keymap("n", "<leader>bd", function() -- delete buffer
vim.cmd("bd")
vim.cmd("echo 'Buffer deleted'")
end)
vim.keymap.set("n", "i", function()
if vim.fn.getline("."):match("^%s*$") then
return [["_cc]]
else
return "i"
end
end, { expr = true, desc = "Inent properly on empty lines" })
vim.keymap.set("n", "a", function()
if vim.fn.getline("."):match("^%s*$") then
return [["_cc]]
else
return "a"
end
end, { expr = true, desc = "Indent properly on empty lines" })
vim.keymap.set("n", "A", function()
if vim.fn.getline("."):match("^%s*$") then
return [["_cc]]
else
return "A"
end
end, { expr = true, desc = "Indent properly on empty lines" })
-- C-BS for deleting whole word in insert mode
vim.keymap.set("i", "<C-BS>", "<C-W>", { noremap = true })
-- Keybinds for MiniSessions
vim.keymap.set("n", "<leader>qj", function() -- quit and save session local
MiniSessions.write(".session")
vim.cmd("wqa")
end, { noremap = true })
vim.keymap.set("n", "<leader>qd", function() -- quit and delete session
pcall(MiniSessions.delete(".session"))
vim.cmd("wqa")
end, { noremap = true })
-- lg keybind
Keymap("n", "<leader>l", function()
Snacks.lazygit.open()
end)
-- Autocommand to check git status
vim.api.nvim_create_autocmd("VimEnter", {
callback = function()
-- Verify if the current directory is a git repo
local is_git = os.execute("git rev-parse --is-inside-work-tree > /dev/null 2>&1")
if is_git ~= 0 then
return
end
-- Perform an async fetch to avoid startup lag
vim.fn.jobstart("git fetch", {
on_exit = function()
-- Get the number of commits the remote is ahead of local HEAD
local count = vim.fn.system("git rev-list --count HEAD..@{u} 2>/dev/null"):gsub("%s+", "")
if count ~= "" and tonumber(count) > 0 then
vim.schedule(function()
vim.notify(
"󰊢 " .. count .. " new commit(s) available on remote.",
vim.log.levels.INFO,
{ title = "Git Status", icon = "󰊢" }
)
end)
end
end,
})
end,
})
-- Keybind to check diags from linter
vim.api.nvim_set_keymap("n", "<leader>d", "<cmd>lua vim.diagnostic.open_float()<CR>", { noremap = true, silent = true })
-- Undotree
vim.cmd("packadd nvim.undotree")
vim.keymap.set("n", "<leader>u", require("undotree").open)