-- Set mapleader vim.g.mapleader = "" vim.g.maplocalleader = "," -- Lazy require("config.lazy") -- Line numbers vim.opt.cursorline = true vim.wo.relativenumber = true 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 vim.o.winborder = "rounded" -- Sane tab management vim.opt.tabstop = 2 vim.opt.softtabstop = 2 vim.opt.shiftwidth = 2 vim.opt.expandtab = false -- Undo management vim.opt.swapfile = false vim.opt.backup = false vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir" vim.opt.undofile = true -- Better Highlighting vim.opt.hlsearch = false 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", "") Keymap("n", "q:", ":") Keymap("n", "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" }) -- C-BS for deleting whole word in insert mode vim.keymap.set("i", "", "", { noremap = true }) -- Keybinds for MiniSessions vim.keymap.set("n", "qj", function() -- quit and save session local MiniSessions.write(".session") vim.cmd("wqa") end, { noremap = true }) vim.keymap.set("n", "qd", function() -- quit and delete session pcall(MiniSessions.delete(".session")) vim.cmd("wqa") end, { noremap = true }) -- lg keybind Keymap("n", "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, })