From 25aded9685685e3b065f92ccac512493a1e7091d Mon Sep 17 00:00:00 2001 From: Harivansh Rathi Date: Fri, 20 Feb 2026 22:34:08 -0500 Subject: [PATCH] clean config --- after/plugin/lsp.lua | 34 +++---- init.lua | 88 ++++++++++-------- lazy-lock.json | 1 - lua/config/lsp.lua | 36 +++----- lua/config/statusline.lua | 139 ---------------------------- lua/lsp/lua_ls.lua | 21 +---- lua/lsp/pyright.lua | 5 +- lua/lsp/rust_analyzer.lua | 23 ++--- lua/lsp/ts_ls.lua | 5 +- lua/plugins/editor.lua | 117 ++++++++++------------- lua/plugins/fzf.lua | 138 +++++++++++++--------------- lua/plugins/git.lua | 184 ++++++++++++++++--------------------- lua/plugins/lsp.lua | 3 +- lua/plugins/oil.lua | 78 ++++++++-------- lua/plugins/treesitter.lua | 147 ++++++++++++----------------- lua/plugins/ui.lua | 182 ++++++++---------------------------- plugin/autocmds.lua | 55 +++++------ plugin/keymaps.lua | 42 ++++----- plugin/options.lua | 22 ++--- 19 files changed, 468 insertions(+), 852 deletions(-) delete mode 100644 lua/config/statusline.lua diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index 2ecfa1e..b14a803 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -1,32 +1,32 @@ -local lsp_config = require("config.lsp") +local lsp = require('config.lsp') -vim.lsp.config("*", { - capabilities = lsp_config.capabilities(), +vim.lsp.config('*', { + capabilities = lsp.capabilities(), }) -vim.api.nvim_create_autocmd("LspAttach", { - group = vim.api.nvim_create_augroup("UserLspConfig", {}), +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('UserLspConfig', {}), callback = function(ev) local client = vim.lsp.get_client_by_id(ev.data.client_id) if client then - lsp_config.on_attach(client, ev.buf) + lsp.on_attach(client, ev.buf) end end, }) for _, server in ipairs({ - "lua_ls", - "pyright", - "ts_ls", - "rust_analyzer", - "gopls", - "clangd", - "bashls", - "jsonls", - "html", - "cssls", + 'lua_ls', + 'pyright', + 'ts_ls', + 'rust_analyzer', + 'gopls', + 'clangd', + 'bashls', + 'jsonls', + 'html', + 'cssls', }) do - local ok, config = pcall(require, "lsp." .. server) + local ok, config = pcall(require, 'lsp.' .. server) if ok then vim.lsp.config(server, config) end diff --git a/init.lua b/init.lua index 6a79e53..cab1c4a 100644 --- a/init.lua +++ b/init.lua @@ -1,49 +1,59 @@ --- Set leader keys before lazy -vim.g.mapleader = " " -vim.g.maplocalleader = "," +vim.g.mapleader = ' ' +vim.g.maplocalleader = ',' --- Global mapping helpers -_G.map = function(mode, lhs, rhs, opts) - opts = opts or {} - opts.silent = opts.silent ~= false - vim.keymap.set(mode, lhs, rhs, opts) +function _G.map(mode, lhs, rhs, opts) + vim.keymap.set(mode, lhs, rhs, vim.tbl_extend('keep', opts or {}, { silent = true })) end -_G.bmap = function(buf, mode, lhs, rhs, opts) - opts = opts or {} - opts.buffer = buf - opts.silent = opts.silent ~= false - vim.keymap.set(mode, lhs, rhs, opts) +function _G.bmap(mode, lhs, rhs, opts) + _G.map(mode, lhs, rhs, vim.tbl_extend('force', opts or {}, { buffer = 0 })) end --- Bootstrap lazy.nvim -local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +local disabled_plugins = { + '2html_plugin', + 'bugreport', + 'getscript', + 'getscriptPlugin', + 'gzip', + 'logipat', + 'matchit', + 'matchparen', + 'netrw', + 'netrwFileHandlers', + 'netrwPlugin', + 'netrwSettings', + 'optwin', + 'rplugin', + 'rrhelper', + 'synmenu', + 'tar', + 'tarPlugin', + 'tohtml', + 'tutor', + 'vimball', + 'vimballPlugin', + 'zip', + 'zipPlugin', +} + +for _, plugin in ipairs(disabled_plugins) do + vim.g['loaded_' .. plugin] = 1 +end + +local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim' if not vim.uv.fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", - lazypath, - }) + vim.fn.system({ + 'git', + 'clone', + '--filter=blob:none', + '--branch=stable', + 'https://github.com/folke/lazy.nvim.git', + lazypath, + }) end vim.opt.rtp:prepend(lazypath) --- Load plugins -require("lazy").setup("plugins", { - defaults = { lazy = true }, - performance = { - rtp = { - disabled_plugins = { - "gzip", - "matchit", - "matchparen", - "netrwPlugin", - "tarPlugin", - "tohtml", - "zipPlugin", - }, - }, - }, +require('lazy').setup('plugins', { + defaults = { lazy = false }, + change_detection = { enabled = false }, }) diff --git a/lazy-lock.json b/lazy-lock.json index 76cc497..54cd768 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,5 +1,4 @@ { - "dashboard-nvim": { "branch": "master", "commit": "0775e567b6c0be96d01a61795f7b64c1758262f6" }, "diffs.nvim": { "branch": "main", "commit": "b1abfe4f4a164ad776148ca36f852df4f1e4014e" }, "flash.nvim": { "branch": "main", "commit": "fcea7ff883235d9024dc41e638f164a450c14ca2" }, "fzf-lua": { "branch": "main", "commit": "b2c0603216adb92c6bba81053bc996d7ae95b77a" }, diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 94e164e..e7790e5 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -1,31 +1,21 @@ --- Shared LSP utilities local M = {} --- Set up buffer-local keymaps when LSP attaches -function M.on_attach(client, bufnr) - local opts = { buffer = bufnr, silent = true } +function M.on_attach(_, bufnr) + local function buf(mode, lhs, rhs) + bmap(mode, lhs, rhs, { buffer = bufnr }) + end - -- Navigation - vim.keymap.set("n", "gd", vim.lsp.buf.definition, vim.tbl_extend("force", opts, { desc = "Go to definition" })) - vim.keymap.set("n", "gD", vim.lsp.buf.declaration, vim.tbl_extend("force", opts, { desc = "Go to declaration" })) - vim.keymap.set("n", "", vim.lsp.buf.definition, vim.tbl_extend("force", opts, { desc = "Go to definition" })) - vim.keymap.set("n", "gi", vim.lsp.buf.implementation, vim.tbl_extend("force", opts, { desc = "Go to implementation" })) - vim.keymap.set("n", "gr", vim.lsp.buf.references, vim.tbl_extend("force", opts, { desc = "Go to references" })) - - -- Documentation - vim.keymap.set("n", "K", vim.lsp.buf.hover, vim.tbl_extend("force", opts, { desc = "Hover documentation" })) - - -- Refactoring - vim.keymap.set("n", "rn", vim.lsp.buf.rename, vim.tbl_extend("force", opts, { desc = "Rename symbol" })) - vim.keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, vim.tbl_extend("force", opts, { desc = "Code action" })) - - -- Formatting - vim.keymap.set("n", "f", function() - vim.lsp.buf.format({ async = true }) - end, vim.tbl_extend("force", opts, { desc = "Format buffer" })) + buf('n', 'gd', vim.lsp.buf.definition) + buf('n', 'gD', vim.lsp.buf.declaration) + buf('n', '', vim.lsp.buf.definition) + buf('n', 'gi', vim.lsp.buf.implementation) + buf('n', 'gr', vim.lsp.buf.references) + buf('n', 'K', vim.lsp.buf.hover) + buf('n', 'rn', vim.lsp.buf.rename) + buf({ 'n', 'v' }, 'ca', vim.lsp.buf.code_action) + buf('n', 'f', function() vim.lsp.buf.format({ async = true }) end) end --- Return default capabilities for LSP servers function M.capabilities() return vim.lsp.protocol.make_client_capabilities() end diff --git a/lua/config/statusline.lua b/lua/config/statusline.lua deleted file mode 100644 index 1a13703..0000000 --- a/lua/config/statusline.lua +++ /dev/null @@ -1,139 +0,0 @@ --- Minimal custom statusline -local M = {} - --- Mode mapping -local mode_map = { - n = "NORMAL", - no = "N-PENDING", - nov = "N-PENDING", - noV = "N-PENDING", - ["no\22"] = "N-PENDING", - niI = "NORMAL", - niR = "NORMAL", - niV = "NORMAL", - nt = "NORMAL", - ntT = "NORMAL", - v = "VISUAL", - vs = "VISUAL", - V = "V-LINE", - Vs = "V-LINE", - ["\22"] = "V-BLOCK", - ["\22s"] = "V-BLOCK", - s = "SELECT", - S = "S-LINE", - ["\19"] = "S-BLOCK", - i = "INSERT", - ic = "INSERT", - ix = "INSERT", - R = "REPLACE", - Rc = "REPLACE", - Rx = "REPLACE", - Rv = "V-REPLACE", - Rvc = "V-REPLACE", - Rvx = "V-REPLACE", - c = "COMMAND", - cv = "EX", - ce = "EX", - r = "REPLACE", - rm = "MORE", - ["r?"] = "CONFIRM", - ["!"] = "SHELL", - t = "TERMINAL", -} - --- Get current mode indicator -local function get_mode() - local mode = vim.api.nvim_get_mode().mode - return mode_map[mode] or mode -end - --- Get git branch from gitsigns -local function get_git_branch() - local branch = vim.b.gitsigns_head - if branch and branch ~= "" then - return " " .. branch - end - return "" -end - --- Get filename with modified indicator -local function get_filename() - local filename = vim.fn.expand("%:t") - if filename == "" then - filename = "[No Name]" - end - - local modified = vim.bo.modified and " [+]" or "" - local readonly = vim.bo.readonly and " [RO]" or "" - - return filename .. modified .. readonly -end - --- Get file path (relative to cwd) -local function get_filepath() - local filepath = vim.fn.expand("%:~:.") - if filepath == "" then - return "" - end - return filepath -end - --- Get current position -local function get_position() - local line = vim.fn.line(".") - local col = vim.fn.col(".") - local total = vim.fn.line("$") - return string.format("%d:%d/%d", line, col, total) -end - --- Get filetype -local function get_filetype() - local ft = vim.bo.filetype - if ft == "" then - return "" - end - return ft -end - --- Build the statusline -function M.statusline() - local parts = {} - - -- Left side - table.insert(parts, " " .. get_mode() .. " ") - table.insert(parts, get_git_branch()) - - local filepath = get_filepath() - if filepath ~= "" then - table.insert(parts, " " .. filepath) - end - - -- Modified indicator - if vim.bo.modified then - table.insert(parts, " [+]") - end - - -- Separator - table.insert(parts, "%=") - - -- Right side - local ft = get_filetype() - if ft ~= "" then - table.insert(parts, ft .. " ") - end - - table.insert(parts, get_position() .. " ") - - return table.concat(parts, "") -end - --- Setup function to configure the statusline -function M.setup() - -- Use the %!v:lua.require() pattern - vim.o.statusline = "%!v:lua.require('config.statusline').statusline()" - - -- Ensure statusline is always shown - vim.o.laststatus = 2 -end - -return M diff --git a/lua/lsp/lua_ls.lua b/lua/lsp/lua_ls.lua index 20d356f..a796d35 100644 --- a/lua/lsp/lua_ls.lua +++ b/lua/lsp/lua_ls.lua @@ -1,25 +1,14 @@ --- Lua language server configuration return { settings = { Lua = { - diagnostics = { - globals = { "vim" }, - }, - runtime = { - version = "LuaJIT", - }, + diagnostics = { globals = { 'vim' } }, + runtime = { version = 'LuaJIT' }, workspace = { checkThirdParty = false, - library = { - vim.env.VIMRUNTIME, - }, - }, - telemetry = { - enable = false, - }, - hint = { - enable = true, + library = { vim.env.VIMRUNTIME }, }, + telemetry = { enable = false }, + hint = { enable = true }, }, }, } diff --git a/lua/lsp/pyright.lua b/lua/lsp/pyright.lua index 4916d5a..4764cd0 100644 --- a/lua/lsp/pyright.lua +++ b/lua/lsp/pyright.lua @@ -1,12 +1,11 @@ --- Pyright (Python) language server configuration return { settings = { python = { analysis = { - typeCheckingMode = "basic", + typeCheckingMode = 'basic', autoSearchPaths = true, useLibraryCodeForTypes = true, - diagnosticMode = "workspace", + diagnosticMode = 'workspace', }, }, }, diff --git a/lua/lsp/rust_analyzer.lua b/lua/lsp/rust_analyzer.lua index e263d50..bc86149 100644 --- a/lua/lsp/rust_analyzer.lua +++ b/lua/lsp/rust_analyzer.lua @@ -1,25 +1,16 @@ --- Rust Analyzer configuration with clippy integration return { settings = { - ["rust-analyzer"] = { - checkOnSave = { - command = "clippy", - }, - cargo = { - allFeatures = true, - }, - procMacro = { - enable = true, - }, - diagnostics = { - enable = true, - }, + ['rust-analyzer'] = { + checkOnSave = { command = 'clippy' }, + cargo = { allFeatures = true }, + procMacro = { enable = true }, + diagnostics = { enable = true }, inlayHints = { bindingModeHints = { enable = true }, chainingHints = { enable = true }, closingBraceHints = { enable = true }, - closureReturnTypeHints = { enable = "always" }, - lifetimeElisionHints = { enable = "always" }, + closureReturnTypeHints = { enable = 'always' }, + lifetimeElisionHints = { enable = 'always' }, parameterHints = { enable = true }, typeHints = { enable = true }, }, diff --git a/lua/lsp/ts_ls.lua b/lua/lsp/ts_ls.lua index c24e861..500a110 100644 --- a/lua/lsp/ts_ls.lua +++ b/lua/lsp/ts_ls.lua @@ -1,9 +1,8 @@ --- TypeScript language server configuration return { settings = { typescript = { inlayHints = { - includeInlayParameterNameHints = "all", + includeInlayParameterNameHints = 'all', includeInlayParameterNameHintsWhenArgumentMatchesName = false, includeInlayFunctionParameterTypeHints = true, includeInlayVariableTypeHints = true, @@ -14,7 +13,7 @@ return { }, javascript = { inlayHints = { - includeInlayParameterNameHints = "all", + includeInlayParameterNameHints = 'all', includeInlayParameterNameHintsWhenArgumentMatchesName = false, includeInlayFunctionParameterTypeHints = true, includeInlayVariableTypeHints = true, diff --git a/lua/plugins/editor.lua b/lua/plugins/editor.lua index 74ec1e3..a43b2cd 100644 --- a/lua/plugins/editor.lua +++ b/lua/plugins/editor.lua @@ -1,78 +1,53 @@ return { - -- Autopairs - { - "windwp/nvim-autopairs", - event = "InsertEnter", - config = function() - require("nvim-autopairs").setup({}) - end, - }, - - -- Flash.nvim for navigation - { - "folke/flash.nvim", - event = "VeryLazy", - opts = { - modes = { - search = { - enabled = true, + { + 'windwp/nvim-autopairs', + config = true, + }, + { + 'folke/flash.nvim', + opts = { + modes = { search = { enabled = true } }, }, - }, + config = function(_, opts) + require('flash').setup(opts) + map({ 'n', 'x', 'o' }, 's', function() require('flash').jump() end) + map({ 'n', 'x', 'o' }, 'S', function() require('flash').treesitter() end) + map('o', 'r', function() require('flash').remote() end) + map({ 'o', 'x' }, 'R', function() require('flash').treesitter_search() end) + map('c', '', function() require('flash').toggle() end) + end, }, - keys = { - { "s", mode = { "n", "x", "o" }, function() require("flash").jump() end, desc = "Flash" }, - { "S", mode = { "n", "x", "o" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" }, - { "r", mode = "o", function() require("flash").remote() end, desc = "Remote Flash" }, - { "R", mode = { "o", "x" }, function() require("flash").treesitter_search() end, desc = "Treesitter Search" }, - { "", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" }, + { + 'kylechui/nvim-surround', + config = true, }, - }, - - -- Surround - { - "kylechui/nvim-surround", - version = "*", - event = "VeryLazy", - opts = {}, - }, - - -- Folds - { - "kevinhwang91/nvim-ufo", - dependencies = { "kevinhwang91/promise-async" }, - event = "BufReadPost", - opts = { - provider_selector = function() - return { "treesitter", "indent" } - end, + { + 'kevinhwang91/nvim-ufo', + dependencies = { 'kevinhwang91/promise-async' }, + opts = { + provider_selector = function() + return { 'treesitter', 'indent' } + end, + }, + config = function(_, opts) + require('ufo').setup(opts) + map('n', 'zR', require('ufo').openAllFolds) + map('n', 'zM', require('ufo').closeAllFolds) + end, }, - keys = { - { "zR", function() require("ufo").openAllFolds() end, desc = "Open all folds" }, - { "zM", function() require("ufo").closeAllFolds() end, desc = "Close all folds" }, + { + 'supermaven-inc/supermaven-nvim', + opts = { + keymaps = { + accept_suggestion = '', + clear_suggestion = '', + accept_word = '', + }, + ignore_filetypes = { gitcommit = true }, + color = { + suggestion_color = vim.api.nvim_get_hl(0, { name = 'Comment' }).fg, + cterm = 244, + }, + }, }, - }, - - -- Supermaven inline suggestions (accepted with Tab) - { - "supermaven-inc/supermaven-nvim", - event = "InsertEnter", - config = function(_, opts) - require("supermaven-nvim").setup(opts) - end, - opts = { - keymaps = { - accept_suggestion = "", - clear_suggestion = "", - accept_word = "", - }, - disable_keymaps = false, - ignore_filetypes = { gitcommit = true }, - color = { - suggestion_color = vim.api.nvim_get_hl(0, { name = "Comment" }).fg, - cterm = 244, - }, - log_level = "info", - disable_inline_completion = false, - }, - }, } diff --git a/lua/plugins/fzf.lua b/lua/plugins/fzf.lua index c229cab..d95a03f 100644 --- a/lua/plugins/fzf.lua +++ b/lua/plugins/fzf.lua @@ -1,82 +1,74 @@ ---@param kind 'issue'|'pr' ---@param state 'all'|'open'|'closed' local function gh_picker(kind, state) - if vim.fn.executable("gh") ~= 1 then - vim.notify("gh CLI not found", vim.log.levels.WARN) - return - end - local next_state = ({ all = "open", open = "closed", closed = "all" })[state] - local label = kind == "pr" and "PRs" or "Issues" - require("fzf-lua").fzf_exec(("gh %s list --limit 100 --state %s"):format(kind, state), { - prompt = ("%s (%s)> "):format(label, state), - header = ":: to toggle all/open/closed", - actions = { - ["default"] = function(selected) - local num = selected[1]:match("^#?(%d+)") - if num then - vim.system({ "gh", kind, "view", num, "--web" }) - end - end, - ["ctrl-o"] = function() - gh_picker(kind, next_state) - end, - }, - }) + if vim.fn.executable('gh') ~= 1 then + vim.notify('gh CLI not found', vim.log.levels.WARN) + return + end + local next_state = ({ all = 'open', open = 'closed', closed = 'all' })[state] + local label = kind == 'pr' and 'PRs' or 'Issues' + require('fzf-lua').fzf_exec(('gh %s list --limit 100 --state %s'):format(kind, state), { + prompt = ('%s (%s)> '):format(label, state), + header = ':: to toggle all/open/closed', + actions = { + ['default'] = function(selected) + local num = selected[1]:match('^#?(%d+)') + if num then + vim.system({ 'gh', kind, 'view', num, '--web' }) + end + end, + ['ctrl-o'] = function() + gh_picker(kind, next_state) + end, + }, + }) end return { - "ibhagwan/fzf-lua", - dependencies = { "nvim-tree/nvim-web-devicons" }, - cmd = "FzfLua", - keys = { - -- Main keybinds - { - "", - function() - local fzf = require("fzf-lua") - local git_dir = vim.fn.system("git rev-parse --git-dir 2>/dev/null"):gsub("\n", "") - if vim.v.shell_error == 0 and git_dir ~= "" then - fzf.git_files() - else - fzf.files() - end - end, - desc = "Find files", - }, + 'ibhagwan/fzf-lua', + dependencies = { 'nvim-tree/nvim-web-devicons' }, + config = function(_, opts) + require('fzf-lua').setup(opts) - -- Leader keybinds - { "ff", function() require("fzf-lua").files() end, desc = "Files" }, - { "fg", function() require("fzf-lua").live_grep() end, desc = "Live grep" }, - { "fb", function() require("fzf-lua").buffers() end, desc = "Buffers" }, - { "fh", function() require("fzf-lua").help_tags() end, desc = "Help tags" }, - { "fr", function() require("fzf-lua").resume() end, desc = "Resume last search" }, - { "fo", function() require("fzf-lua").oldfiles() end, desc = "Recent files" }, - { "fc", function() require("fzf-lua").commands() end, desc = "Commands" }, - { "fk", function() require("fzf-lua").keymaps() end, desc = "Keymaps" }, - { "f/", function() require("fzf-lua").search_history() end, desc = "Search history" }, - { "f:", function() require("fzf-lua").command_history() end, desc = "Command history" }, - { "fe", function() require("fzf-lua").files({ cwd = "~/.config" }) end, desc = "Config files" }, - -- Quickfix/loclist - { "gq", function() require("fzf-lua").quickfix() end, desc = "Quickfix" }, - { "gl", function() require("fzf-lua").loclist() end, desc = "Loclist" }, - -- Git - { "GB", function() require("fzf-lua").git_branches() end, desc = "Git branches" }, - { "Gc", function() require("fzf-lua").git_commits() end, desc = "Git commits" }, - { "Gs", function() require("fzf-lua").git_status() end, desc = "Git status" }, - { "Gp", function() gh_picker("pr", "open") end, desc = "GitHub PRs" }, - { "Gi", function() gh_picker("issue", "open") end, desc = "GitHub issues" }, - }, - opts = { - "default-title", - winopts = { - border = "single", - preview = { - layout = "vertical", - vertical = "down:50%", - }, + map('n', '', function() + local fzf = require('fzf-lua') + local git_dir = vim.fn.system('git rev-parse --git-dir 2>/dev/null'):gsub('\n', '') + if vim.v.shell_error == 0 and git_dir ~= '' then + fzf.git_files() + else + fzf.files() + end + end) + map('n', 'ff', 'FzfLua files') + map('n', 'fg', 'FzfLua live_grep') + map('n', 'fb', 'FzfLua buffers') + map('n', 'fh', 'FzfLua help_tags') + map('n', 'fr', 'FzfLua resume') + map('n', 'fo', 'FzfLua oldfiles') + map('n', 'fc', 'FzfLua commands') + map('n', 'fk', 'FzfLua keymaps') + map('n', 'f/', 'FzfLua search_history') + map('n', 'f:', 'FzfLua command_history') + map('n', 'fe', 'FzfLua files cwd=~/.config') + map('n', 'gq', 'FzfLua quickfix') + map('n', 'gl', 'FzfLua loclist') + map('n', 'GB', 'FzfLua git_branches') + map('n', 'Gc', 'FzfLua git_commits') + map('n', 'Gs', 'FzfLua git_status') + map('n', 'Gp', function() gh_picker('pr', 'open') end) + map('n', 'Gi', function() gh_picker('issue', 'open') end) + end, + opts = { + 'default-title', + winopts = { + border = 'single', + preview = { + layout = 'vertical', + vertical = 'down:50%', + }, + }, + fzf_opts = { + ['--layout'] = 'reverse', + }, }, - fzf_opts = { - ["--layout"] = "reverse", - }, - }, } diff --git a/lua/plugins/git.lua b/lua/plugins/git.lua index 515d71c..54dad5a 100644 --- a/lua/plugins/git.lua +++ b/lua/plugins/git.lua @@ -1,114 +1,88 @@ -local function current_file_location() - local root = vim.trim(vim.fn.system("git rev-parse --show-toplevel")) - if vim.v.shell_error ~= 0 or root == "" then - return nil - end - - local path = vim.api.nvim_buf_get_name(0) - if path == "" then - return nil - end - - local prefix = root .. "/" - if path:sub(1, #prefix) ~= prefix then - return nil - end - - local rel = path:sub(#prefix + 1) - return ("%s:%d"):format(rel, vim.fn.line(".")) +local function file_loc() + local root = vim.trim(vim.fn.system('git rev-parse --show-toplevel')) + if vim.v.shell_error ~= 0 or root == '' then + return nil + end + local path = vim.api.nvim_buf_get_name(0) + if path == '' or path:sub(1, #root + 1) ~= root .. '/' then + return nil + end + return ('%s:%d'):format(path:sub(#root + 2), vim.fn.line('.')) end local function gh_browse() - if vim.fn.executable("gh") ~= 1 then - vim.notify("gh CLI not found", vim.log.levels.WARN) - return - end - - local loc = current_file_location() - if loc then - vim.system({ "gh", "browse", loc }) - return - end - vim.system({ "gh", "browse" }) + if vim.fn.executable('gh') ~= 1 then + vim.notify('gh CLI not found', vim.log.levels.WARN) + return + end + local loc = file_loc() + if loc then + vim.system({ 'gh', 'browse', loc }) + else + vim.system({ 'gh', 'browse' }) + end end return { - -- Fugitive: The gold standard for Git in Vim - { - "tpope/vim-fugitive", - cmd = { "Git", "G", "Gread", "Gwrite", "Gdiffsplit", "Gvdiffsplit", "Gblame" }, - keys = { - { "gg", "Gitonly", desc = "Git status (fullscreen)" }, - { "gc", "Git commit", desc = "Git commit" }, - { "gp", "Git push", desc = "Git push" }, - { "gl", "Git pull", desc = "Git pull" }, - { "gb", "Git blame", desc = "Git blame" }, - { "gd", "Gvdiffsplit", desc = "Git diff vertical" }, - { "gr", "Gread", desc = "Git checkout file" }, - { "gw", "Gwrite", desc = "Git add file" }, - { "go", gh_browse, desc = "Open in GitHub" }, + { + 'tpope/vim-fugitive', + config = function() + map('n', 'gg', 'Gitonly') + map('n', 'gc', 'Git commit') + map('n', 'gp', 'Git push') + map('n', 'gl', 'Git pull') + map('n', 'gb', 'Git blame') + map('n', 'gd', 'Gvdiffsplit') + map('n', 'gr', 'Gread') + map('n', 'gw', 'Gwrite') + map({ 'n', 'v' }, 'go', gh_browse) + end, }, - }, - - -- Gitsigns: Git info in the gutter - { - "lewis6991/gitsigns.nvim", - event = { "BufReadPre", "BufNewFile" }, - opts = { - signs = { - add = { text = "██" }, - change = { text = "██" }, - delete = { text = "▄▄" }, - topdelete = { text = "▀▀" }, - changedelete = { text = "██" }, - }, - signs_staged = { - add = { text = "▓▓" }, - change = { text = "▓▓" }, - delete = { text = "▄▄" }, - topdelete = { text = "▀▀" }, - changedelete = { text = "▓▓" }, - }, - signs_staged_enable = true, - signcolumn = true, - numhl = false, - linehl = false, -- disabled - let colorscheme handle - word_diff = false, - current_line_blame = false, - current_line_blame_opts = { - delay = 500, - }, - }, - keys = { - { "]g", "Gitsigns next_hunk", desc = "Next hunk" }, - { "[g", "Gitsigns prev_hunk", desc = "Prev hunk" }, - { "ghs", "Gitsigns stage_hunk", desc = "Stage hunk" }, - { "ghr", "Gitsigns reset_hunk", desc = "Reset hunk" }, - { "ghp", "Gitsigns preview_hunk", desc = "Preview hunk" }, - { "gB", "Gitsigns toggle_current_line_blame", desc = "Toggle line blame" }, - }, - }, - - -- Diffs.nvim: Better diff highlighting - { - "barrettruth/diffs.nvim", - lazy = false, - init = function() - vim.g.diffs = { - fugitive = { - enabled = true, - horizontal = false, - vertical = false, + { + 'lewis6991/gitsigns.nvim', + opts = { + signs = { + add = { text = '██' }, + change = { text = '██' }, + delete = { text = '▄▄' }, + topdelete = { text = '▀▀' }, + changedelete = { text = '██' }, + }, + signs_staged = { + add = { text = '▓▓' }, + change = { text = '▓▓' }, + delete = { text = '▄▄' }, + topdelete = { text = '▀▀' }, + changedelete = { text = '▓▓' }, + }, + signs_staged_enable = true, }, - hide_prefix = true, - highlights = { - gutter = true, - blend_alpha = 0.4, - intra = { - enabled = true, - }, - }, - } - end, - }, + config = function(_, opts) + require('gitsigns').setup(opts) + map('n', ']g', 'Gitsigns next_hunk') + map('n', '[g', 'Gitsigns prev_hunk') + map('n', 'ghs', 'Gitsigns stage_hunk') + map('n', 'ghr', 'Gitsigns reset_hunk') + map('n', 'ghp', 'Gitsigns preview_hunk') + map('n', 'gB', 'Gitsigns toggle_current_line_blame') + end, + }, + { + 'barrettruth/diffs.nvim', + init = function() + vim.g.diffs = { + fugitive = { + enabled = true, + horizontal = false, + vertical = false, + }, + hide_prefix = true, + highlights = { + gutter = true, + blend_alpha = 0.4, + intra = { enabled = true }, + }, + } + end, + }, } diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 65bbe2c..39f8bba 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -1,3 +1,4 @@ return { - { "neovim/nvim-lspconfig", lazy = false }, + 'neovim/nvim-lspconfig', + lazy = false, } diff --git a/lua/plugins/oil.lua b/lua/plugins/oil.lua index 7214e15..6fac969 100644 --- a/lua/plugins/oil.lua +++ b/lua/plugins/oil.lua @@ -1,44 +1,40 @@ return { - "stevearc/oil.nvim", - dependencies = { "nvim-tree/nvim-web-devicons", "malewicz1337/oil-git.nvim" }, - cmd = "Oil", - event = 'VeryLazy', - keys = { - { "-", "Oil", desc = "Open parent directory" }, - { "e", "Oil", desc = "Open file explorer" }, - }, - config = function(_, opts) - require("oil").setup(opts) - require("oil-git").setup({ - show_ignored_files = false, - show_ignored_directories = false, - debounce_ms = 300, - }) - vim.api.nvim_create_autocmd("BufEnter", { - pattern = "oil://*", - callback = function() - local dir = require("oil").get_current_dir() - if dir then - vim.cmd.lcd(dir) - end - end, - }) - end, - opts = { - default_file_explorer = true, -- nvim . opens oil - columns = { "icon" }, - view_options = { - show_hidden = true, + 'stevearc/oil.nvim', + dependencies = { 'nvim-tree/nvim-web-devicons', 'malewicz1337/oil-git.nvim' }, + config = function(_, opts) + require('oil').setup(opts) + require('oil-git').setup({ + show_ignored_files = false, + show_ignored_directories = false, + debounce_ms = 300, + }) + vim.api.nvim_create_autocmd('BufEnter', { + callback = function() + if vim.bo.filetype == '' then + local path = vim.fn.expand('%:p') + if vim.fn.isdirectory(path) == 1 then + vim.cmd('Oil ' .. path) + end + end + end, + group = vim.api.nvim_create_augroup('AOil', { clear = true }), + }) + map('n', '-', 'Oil') + map('n', 'e', 'Oil') + end, + opts = { + default_file_explorer = true, + columns = { 'icon' }, + view_options = { show_hidden = true }, + keymaps = { + ['g?'] = 'actions.show_help', + [''] = 'actions.select', + [''] = 'actions.select_vsplit', + [''] = 'actions.select_split', + [''] = 'actions.preview', + [''] = 'actions.close', + ['-'] = 'actions.parent', + ['g.'] = 'actions.toggle_hidden', + }, }, - keymaps = { - ["g?"] = "actions.show_help", - [""] = "actions.select", - [""] = "actions.select_vsplit", - [""] = "actions.select_split", - [""] = "actions.preview", - [""] = "actions.close", - ["-"] = "actions.parent", - ["g."] = "actions.toggle_hidden", - }, - }, } diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua index bf8c9c2..7c78733 100644 --- a/lua/plugins/treesitter.lua +++ b/lua/plugins/treesitter.lua @@ -1,92 +1,61 @@ return { - -- Treesitter for syntax highlighting and code understanding - { - "nvim-treesitter/nvim-treesitter", - build = ":TSUpdate", - event = { "BufReadPost", "BufNewFile" }, - dependencies = { - "nvim-treesitter/nvim-treesitter-textobjects", + { + 'nvim-treesitter/nvim-treesitter', + build = ':TSUpdate', + dependencies = { 'nvim-treesitter/nvim-treesitter-textobjects' }, + config = function() + require('nvim-treesitter.configs').setup({ + auto_install = true, + highlight = { enable = true }, + indent = { enable = true }, + textobjects = { + select = { + enable = true, + lookahead = true, + keymaps = { + ['af'] = '@function.outer', + ['if'] = '@function.inner', + ['ac'] = '@class.outer', + ['ic'] = '@class.inner', + ['aa'] = '@parameter.outer', + ['ia'] = '@parameter.inner', + ['ai'] = '@conditional.outer', + ['ii'] = '@conditional.inner', + ['al'] = '@loop.outer', + ['il'] = '@loop.inner', + ['ab'] = '@block.outer', + ['ib'] = '@block.inner', + }, + }, + move = { + enable = true, + set_jumps = true, + goto_next_start = { + [']f'] = '@function.outer', + [']c'] = '@class.outer', + [']a'] = '@parameter.inner', + }, + goto_next_end = { + [']F'] = '@function.outer', + [']C'] = '@class.outer', + }, + goto_previous_start = { + ['[f'] = '@function.outer', + ['[c'] = '@class.outer', + ['[a'] = '@parameter.inner', + }, + goto_previous_end = { + ['[F'] = '@function.outer', + ['[C'] = '@class.outer', + }, + }, + swap = { + enable = true, + swap_next = { ['sn'] = '@parameter.inner' }, + swap_previous = { ['sp'] = '@parameter.inner' }, + }, + }, + }) + end, }, - config = function() - require("nvim-treesitter.configs").setup({ - ensure_installed = { - "lua", - "vim", - "vimdoc", - "query", - "javascript", - "typescript", - "tsx", - "python", - "html", - "css", - "json", - "yaml", - "markdown", - "markdown_inline", - "bash", - "regex", - }, - auto_install = true, - highlight = { - enable = true, - additional_vim_regex_highlighting = false, - }, - indent = { - enable = true, - }, - textobjects = { - select = { - enable = true, - lookahead = true, - keymaps = { - ["af"] = "@function.outer", - ["if"] = "@function.inner", - ["ac"] = "@class.outer", - ["ic"] = "@class.inner", - ["aa"] = "@parameter.outer", - ["ia"] = "@parameter.inner", - ["ai"] = "@conditional.outer", - ["ii"] = "@conditional.inner", - ["al"] = "@loop.outer", - ["il"] = "@loop.inner", - ["ab"] = "@block.outer", - ["ib"] = "@block.inner", - }, - }, - move = { - enable = true, - set_jumps = true, - goto_next_start = { - ["]f"] = "@function.outer", - ["]c"] = "@class.outer", - ["]a"] = "@parameter.inner", - }, - goto_next_end = { - ["]F"] = "@function.outer", - ["]C"] = "@class.outer", - }, - goto_previous_start = { - ["[f"] = "@function.outer", - ["[c"] = "@class.outer", - ["[a"] = "@parameter.inner", - }, - goto_previous_end = { - ["[F"] = "@function.outer", - ["[C"] = "@class.outer", - }, - }, - swap = { - enable = true, - swap_next = { - ["sn"] = "@parameter.inner", - }, - swap_previous = { - ["sp"] = "@parameter.inner", - }, - }, - }, - }) - end, - }, } diff --git a/lua/plugins/ui.lua b/lua/plugins/ui.lua index f69ad1d..6289716 100644 --- a/lua/plugins/ui.lua +++ b/lua/plugins/ui.lua @@ -1,146 +1,42 @@ return { - -- Gruvbox colorscheme - { - "ellisonleao/gruvbox.nvim", - lazy = false, - priority = 1000, - config = function() - require("gruvbox").setup({ - terminal_colors = true, - undercurl = true, - underline = false, - bold = true, - italic = { - strings = false, - emphasis = false, - comments = true, - operators = false, - folds = false, - }, - strikethrough = true, - invert_selection = false, - invert_signs = false, - invert_tabline = false, - invert_intend_guides = false, - inverse = true, - contrast = "hard", - palette_overrides = {}, - overrides = { - MatchParen = { bold = true, underline = true, bg = "" }, - }, - dim_inactive = false, - transparent_mode = true, - }) - vim.cmd.colorscheme("gruvbox") - - end, - }, - - -- Lualine statusline - { - "nvim-lualine/lualine.nvim", - lazy = false, - dependencies = { "nvim-tree/nvim-web-devicons" }, - config = function() - require("lualine").setup({ - options = { - theme = "gruvbox", - icons_enabled = false, - component_separators = "", - section_separators = "", - }, - sections = { - lualine_a = { "mode" }, - lualine_b = { "branch", "diff" }, - lualine_c = { { "filename", path = 1 } }, - lualine_x = { "diagnostics" }, - lualine_y = { "filetype" }, - lualine_z = { "location" }, - }, - }) - end, - }, - - -- Dashboard - { - "nvimdev/dashboard-nvim", - event = "VimEnter", - dependencies = { "nvim-tree/nvim-web-devicons" }, - config = function() - local header_art = { - " ██▒ █▓ ██▓ ███▄ ▄███▓", - "▓██░ █▒▓██▒▓██▒▀█▀ ██▒", - " ▓██ █▒░▒██▒▓██ ▓██░", - " ▒██ █░░░██░▒██ ▒██ ", - " ▒▀█░ ░██░▒██▒ ░██▒", - " ░ ▐░ ░▓ ░ ▒░ ░ ░", - " ░ ░░ ▒ ░░ ░ ░", - " ░░ ▒ ░░ ░ ", - " ░ ░ ░ ", - " ░ ", - } - local center_items = 6 - local content_height = #header_art + 2 + (center_items * 2) - local win_height = vim.fn.winheight(0) - local padding = math.max(0, math.floor((win_height - content_height) / 2)) - - local header = {} - for _ = 1, padding do - table.insert(header, "") - end - for _, line in ipairs(header_art) do - table.insert(header, line) - end - table.insert(header, "") - table.insert(header, "") - - require("dashboard").setup({ - theme = "doom", - config = { - header = header, - center = { - { - icon = " ", - desc = "Find File ", - key = "f", - action = function() require("fzf-lua").files() end, - }, - { - icon = " ", - desc = "Recent Files ", - key = "r", - action = function() require("fzf-lua").oldfiles() end, - }, - { - icon = " ", - desc = "Find Text ", - key = "g", - action = function() require("fzf-lua").live_grep() end, - }, - { - icon = " ", - desc = "File Explorer ", - key = "e", - action = function() vim.cmd("Oil") end, - }, - { - icon = " ", - desc = "Quit ", - key = "q", - action = function() vim.cmd("quit") end, - }, - }, - footer = {}, - }, - }) - end, - }, - - -- Nonicons font icons for nvim-web-devicons - { - "barrettruth/nonicons.nvim", + { + 'ellisonleao/gruvbox.nvim', lazy = false, - dependencies = { "nvim-tree/nvim-web-devicons" }, - }, - + priority = 1000, + config = function() + require('gruvbox').setup({ + contrast = 'hard', + transparent_mode = true, + italic = { comments = true }, + overrides = { + MatchParen = { bold = true, underline = true, bg = '' }, + }, + }) + vim.cmd.colorscheme('gruvbox') + end, + }, + { + 'nvim-lualine/lualine.nvim', + dependencies = { 'nvim-tree/nvim-web-devicons' }, + opts = { + options = { + theme = 'gruvbox', + icons_enabled = false, + component_separators = '', + section_separators = '', + }, + sections = { + lualine_a = { 'mode' }, + lualine_b = { 'branch', 'diff' }, + lualine_c = { { 'filename', path = 1 } }, + lualine_x = { 'diagnostics' }, + lualine_y = { 'filetype' }, + lualine_z = { 'location' }, + }, + }, + }, + { + 'barrettruth/nonicons.nvim', + dependencies = { 'nvim-tree/nvim-web-devicons' }, + }, } diff --git a/plugin/autocmds.lua b/plugin/autocmds.lua index 32cc2b9..d993703 100644 --- a/plugin/autocmds.lua +++ b/plugin/autocmds.lua @@ -1,38 +1,31 @@ --- Autocommands local api = vim.api -local augroup = api.nvim_create_augroup("UserAutocmds", { clear = true }) +local augroup = api.nvim_create_augroup('UserAutocmds', { clear = true }) --- Highlight on yank -api.nvim_create_autocmd("TextYankPost", { - group = augroup, - callback = function() - vim.highlight.on_yank({ higroup = "Visual", timeout = 200 }) - end, - desc = "Highlight text on yank", +api.nvim_create_autocmd('TextYankPost', { + group = augroup, + callback = function() + vim.highlight.on_yank({ higroup = 'Visual', timeout = 200 }) + end, }) --- Restore cursor position on file open -api.nvim_create_autocmd("BufReadPost", { - group = augroup, - callback = function() - local excluded = { gitcommit = true, gitrebase = true } - if excluded[vim.bo.filetype] then return end - local mark = api.nvim_buf_get_mark(0, '"') - local line_count = api.nvim_buf_line_count(0) - if mark[1] > 0 and mark[1] <= line_count then - pcall(api.nvim_win_set_cursor, 0, mark) - end - end, - desc = "Restore cursor position", +api.nvim_create_autocmd('BufReadPost', { + group = augroup, + callback = function() + if ({ gitcommit = true, gitrebase = true })[vim.bo.filetype] then + return + end + local mark = api.nvim_buf_get_mark(0, '"') + if mark[1] > 0 and mark[1] <= api.nvim_buf_line_count(0) then + pcall(api.nvim_win_set_cursor, 0, mark) + end + end, }) --- Auto-resize splits on VimResized -api.nvim_create_autocmd("VimResized", { - group = augroup, - callback = function() - local current_tab = vim.fn.tabpagenr() - vim.cmd("tabdo wincmd =") - vim.cmd("tabnext " .. current_tab) - end, - desc = "Auto-resize splits", +api.nvim_create_autocmd('VimResized', { + group = augroup, + callback = function() + local tab = vim.fn.tabpagenr() + vim.cmd('tabdo wincmd =') + vim.cmd('tabnext ' .. tab) + end, }) diff --git a/plugin/keymaps.lua b/plugin/keymaps.lua index b2a78a9..65a4ce4 100644 --- a/plugin/keymaps.lua +++ b/plugin/keymaps.lua @@ -1,29 +1,21 @@ --- Keymaps using global map() helper +map('n', 'w', 'w') +map('n', 'q', 'q') +map('n', '', 'Gitonly') --- File operations -map("n", "w", "w", { desc = "Save file" }) -map("n", "q", "q", { desc = "Quit" }) -map("n", "", "Gitonly", { desc = "Git status (fullscreen)" }) +map('n', '', 'bnext') +map('n', '', 'bprev') +map('n', 'x', 'bdelete') +map('n', 'b', 'enew') --- Buffer navigation -map("n", "", "bnext", { desc = "Next buffer" }) -map("n", "", "bprev", { desc = "Previous buffer" }) -map("n", "x", "bdelete", { desc = "Close buffer" }) -map("n", "b", "enew", { desc = "New buffer" }) +map('n', '', 'h') +map('n', '', 'j') +map('n', '', 'k') +map('n', '', 'l') --- Window navigation -map("n", "", "h", { desc = "Move to left window" }) -map("n", "", "j", { desc = "Move to lower window" }) -map("n", "", "k", { desc = "Move to upper window" }) -map("n", "", "l", { desc = "Move to right window" }) +map('n', 'J', 'mzJ`z') +map('x', 'x', '"_x') +map('x', 'p', '"_dP') +map('n', '', 'nohlsearch') +map('n', 't', 'setlocal wrap!') --- Better defaults -map("n", "J", "mzJ`z", { desc = "Join lines keeping cursor position" }) -map("x", "x", '"_x', { desc = "Delete char without yanking" }) -map("x", "p", '"_dP', { desc = "Paste without yanking replaced text" }) -map("n", "", "nohlsearch", { desc = "Clear search highlight" }) -map("n", "t", "setlocal wrap!", { desc = "Toggle word wrap" }) - - --- Terminal -map("t", "", "", { desc = "Exit terminal mode" }) +map('t', '', '') diff --git a/plugin/options.lua b/plugin/options.lua index 686cc51..6c22d74 100644 --- a/plugin/options.lua +++ b/plugin/options.lua @@ -1,52 +1,42 @@ --- Vim options local o, opt = vim.o, vim.opt --- Line numbers o.number = true o.relativenumber = true --- Indentation o.tabstop = 2 o.shiftwidth = 2 o.expandtab = true o.smartindent = true o.breakindent = true --- Search o.ignorecase = true o.smartcase = true o.hlsearch = false o.incsearch = true --- UI o.termguicolors = true -o.cursorline = false o.scrolloff = 8 -o.signcolumn = "yes:2" +o.signcolumn = 'yes' o.wrap = false o.showmode = false o.laststatus = 3 o.cmdheight = 0 -opt.fillchars = { vert = "│", fold = "─", foldsep = "│", diff = "─" } -opt.shortmess:append("S") +opt.fillchars = { vert = '|', fold = '-', foldsep = '|', diff = '-' } +opt.shortmess:append('S') --- Splits o.splitbelow = true o.splitright = true --- Files o.swapfile = false o.backup = false o.undofile = true -o.undodir = vim.fn.stdpath("data") .. "/undo" +o.undodir = vim.fn.stdpath('data') .. '/undo' --- Folds (nvim-ufo) o.foldlevel = 99 o.foldlevelstart = 99 o.foldenable = true --- Misc o.updatetime = 250 -o.mouse = "a" -o.clipboard = "unnamedplus" +o.mouse = 'a' +o.clipboard = 'unnamedplus'