vim.cmd(":colorscheme catppuccin") vim.opt.number = true vim.opt.relativenumber = true vim.opt.splitbelow = true vim.opt.splitright = true -- Treat hyphens as word separators so this-word becomes two words vim.opt.iskeyword:remove("-") -- Set tab width and use spaces instead of tabs vim.opt.tabstop = 2 vim.opt.shiftwidth = 2 vim.opt.expandtab = true -- Enable copying to clipboard vim.opt.clipboard = "unnamedplus" vim.opt.scrolloff = 999 -- Enable syntax highlighting and smart indentation vim.opt.syntax = "on" vim.opt.smartindent = true -- Highlight the current line vim.opt.cursorline = true -- Makes the virtual edit move and select where there is no character vim.opt.virtualedit = "block" vim.opt.inccommand = "split" vim.opt.ignorecase = true vim.opt.termguicolors = true vim.opt.smartindent = true vim.opt.autoindent = true vim.opt.signcolumn = "yes" vim.opt.colorcolumn = "100" -- vim.opt.showmatch = true vim.opt.cmdheight = 1 vim.opt.completeopt = "menuone,noinsert,noselect" vim.opt.showmode = false local undodir = vim.fn.expand("~/.vim/undodir") if vim.fn.isdirectory(undodir) == 0 then vim.fn.mkdir(undodir, "p") end vim.opt.undodir = undodir vim.opt.updatetime = 300 vim.opt.timeoutlen = 500 vim.opt.ttimeoutlen = 0 vim.opt.autoread = true vim.opt.autowrite = false vim.opt.hidden = true -- allow hidden buffers vim.opt.errorbells = false --vim.opt.backspace = "indent,eal,start" -- better backspace behaviour vim.opt.autochdir = false vim.opt.selection = "inclusive" vim.opt.wrap = false -- ============================================================================ -- STATUSLINE -- ============================================================================ -- Git branch function with caching and Nerd Font icon local cached_branch = "" local last_check = 0 local function git_branch() local now = vim.loop.now() if now - last_check > 5000 then -- Check every 5 seconds cached_branch = vim.fn.system("git branch --show-current 2>/dev/null | tr -d '\n'") last_check = now end if cached_branch ~= "" then return " \u{e725} " .. cached_branch .. " " -- nf-dev-git_branch end return "" end -- File type with Nerd Font icon local function file_type() local ft = vim.bo.filetype local icons = { lua = "\u{e620} ", -- nf-dev-lua python = "\u{e73c} ", -- nf-dev-python javascript = "\u{e74e} ", -- nf-dev-javascript typescript = "\u{e628} ", -- nf-dev-typescript javascriptreact = "\u{e7ba} ", typescriptreact = "\u{e7ba} ", html = "\u{e736} ", -- nf-dev-html5 css = "\u{e749} ", -- nf-dev-css3 scss = "\u{e749} ", json = "\u{e60b} ", -- nf-dev-json markdown = "\u{e73e} ", -- nf-dev-markdown vim = "\u{e62b} ", -- nf-dev-vim sh = "\u{f489} ", -- nf-oct-terminal bash = "\u{f489} ", zsh = "\u{f489} ", rust = "\u{e7a8} ", -- nf-dev-rust go = "\u{e724} ", -- nf-dev-go c = "\u{e61e} ", -- nf-dev-c cpp = "\u{e61d} ", -- nf-dev-cplusplus java = "\u{e738} ", -- nf-dev-java php = "\u{e73d} ", -- nf-dev-php ruby = "\u{e739} ", -- nf-dev-ruby swift = "\u{e755} ", -- nf-dev-swift kotlin = "\u{e634} ", dart = "\u{e798} ", elixir = "\u{e62d} ", haskell = "\u{e777} ", sql = "\u{e706} ", yaml = "\u{f481} ", toml = "\u{e615} ", xml = "\u{f05c} ", dockerfile = "\u{f308} ", -- nf-linux-docker gitcommit = "\u{f418} ", -- nf-oct-git_commit gitconfig = "\u{f1d3} ", -- nf-fa-git vue = "\u{fd42} ", -- nf-md-vuejs svelte = "\u{e697} ", astro = "\u{e628} ", } if ft == "" then return " \u{f15b} " -- nf-fa-file_o end return ((icons[ft] or " \u{f15b} ") .. ft) end -- File size with Nerd Font icon local function file_size() local size = vim.fn.getfsize(vim.fn.expand("%")) if size < 0 then return "" end local size_str if size < 1024 then size_str = size .. "B" elseif size < 1024 * 1024 then size_str = string.format("%.1fK", size / 1024) else size_str = string.format("%.1fM", size / 1024 / 1024) end return " \u{f016} " .. size_str .. " " -- nf-fa-file_o end -- Mode indicators with Nerd Font icons local function mode_icon() local mode = vim.fn.mode() local modes = { n = " \u{f121} NORMAL", i = " \u{f11c} INSERT", v = " \u{f0168} VISUAL", V = " \u{f0168} V-LINE", ["\22"] = " \u{f0168} V-BLOCK", c = " \u{f120} COMMAND", s = " \u{f0c5} SELECT", S = " \u{f0c5} S-LINE", ["\19"] = " \u{f0c5} S-BLOCK", R = " \u{f044} REPLACE", r = " \u{f044} REPLACE", ["!"] = " \u{f489} SHELL", t = " \u{f120} TERMINAL", } return modes[mode] or (" \u{f059} " .. mode) end _G.mode_icon = mode_icon _G.git_branch = git_branch _G.file_type = file_type _G.file_size = file_size vim.cmd([[ highlight StatusLineBold gui=bold cterm=bold ]]) -- Function to change statusline based on window focus local function setup_dynamic_statusline() vim.api.nvim_create_autocmd({ "WinEnter", "BufEnter" }, { callback = function() vim.opt_local.statusline = table.concat({ " ", "%#StatusLineBold#", "%{v:lua.mode_icon()}", "%#StatusLine#", " \u{e0b1} %f %h%m%r", -- nf-pl-left_hard_divider "%{v:lua.git_branch()}", "\u{e0b1} ", -- nf-pl-left_hard_divider "%{v:lua.file_type()}", "\u{e0b1} ", -- nf-pl-left_hard_divider "%{v:lua.file_size()}", "%=", -- Right-align everything after this " \u{f017} %l:%c %P ", -- nf-fa-clock_o for line/col }) end, }) vim.api.nvim_set_hl(0, "StatusLineBold", { bold = true }) vim.api.nvim_create_autocmd({ "WinLeave", "BufLeave" }, { callback = function() vim.opt_local.statusline = " %f %h%m%r \u{e0b1} %{v:lua.file_type()} %= %l:%c %P " end, }) end setup_dynamic_statusline() -- highlight yanked text vim.api.nvim_create_autocmd("TextYankPost", { group = augroup, callback = function() vim.hl.on_yank() end, }) -- return to last cursor position vim.api.nvim_create_autocmd("BufReadPost", { group = augroup, desc = "Restore last cursor position", callback = function() if vim.o.diff then -- except in diff mode return end local last_pos = vim.api.nvim_buf_get_mark(0, '"') -- {line, col} local last_line = vim.api.nvim_buf_line_count(0) local row = last_pos[1] if row < 1 or row > last_line then return end pcall(vim.api.nvim_win_set_cursor, 0, last_pos) end, }) -- wrap, linebreak and spellcheck on markdown and text files vim.api.nvim_create_autocmd("FileType", { group = augroup, pattern = { "markdown", "text", "gitcommit" }, callback = function() vim.opt_local.wrap = true vim.opt_local.linebreak = true vim.opt_local.spell = true end, })