From 1241278b1e0eb88b1b12a90eb1f89880c977609c Mon Sep 17 00:00:00 2001 From: zoomiti Date: Tue, 2 Sep 2025 13:52:59 -0700 Subject: [PATCH] Update to neogit and statusline upgrade --- .config/nvim/init.lua | 99 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 87 insertions(+), 12 deletions(-) diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 7a57993..6b266bc 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -6,8 +6,9 @@ vim.pack.add({ { src = "https://github.com/mrcjkb/rustaceanvim" }, { src = 'https://github.com/folke/which-key.nvim' }, { src = 'https://github.com/LunarWatcher/auto-pairs' }, - { src = 'https://github.com/tpope/vim-fugitive' }, - { src = 'https://github.com/airblade/vim-gitgutter' }, + { src = 'https://github.com/nvim-lua/plenary.nvim' }, + { src = 'https://github.com/NeogitOrg/neogit' }, + { src = 'https://github.com/lewis6991/gitsigns.nvim' }, { src = 'https://github.com/nvim-treesitter/nvim-treesitter' }, { src = 'https://github.com/rayliwell/tree-sitter-rstml' }, { src = 'https://github.com/Saghen/blink.cmp', version = vim.version.range("v1.*") }, @@ -123,15 +124,81 @@ vim.diagnostic.config({ --- Fugitive -vim.keymap.set('n', 'gs', 'G', { desc = "Git Status" }) -vim.keymap.set('n', 'gp', 'G pull', { desc = "Git Pull" }) -vim.keymap.set('n', 'gP', 'G push', { desc = "Git Push" }) -vim.keymap.set('n', 'gP', 'G push', { desc = "Git Push" }) +-- Neogit +vim.keymap.set('n', 'gs', 'Neogit kind=split_above_all', { desc = "Git Status" }) +vim.keymap.set('n', 'gp', 'Neogit pull', { desc = "Git Pull" }) +vim.keymap.set('n', 'gP', 'Neogit push', { desc = "Git Push" }) +require('gitsigns').setup { + on_attach = function(bufnr) + local gitsigns = require('gitsigns') + + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- Navigation + map('n', ']c', function() + if vim.wo.diff then + vim.cmd.normal({ ']c', bang = true }) + else + gitsigns.nav_hunk('next') + end + end, { desc = "next hunk" }) + + map('n', '[c', function() + if vim.wo.diff then + vim.cmd.normal({ '[c', bang = true }) + else + gitsigns.nav_hunk('prev') + end + end, { desc = "prev hunk" }) + + -- Actions + map('n', 'hs', gitsigns.stage_hunk, { desc = "(un)stage hunk" }) + map('n', 'hr', gitsigns.reset_hunk, { desc = "reset hunk" }) + + map('v', 'hs', function() + gitsigns.stage_hunk({ vim.fn.line('.'), vim.fn.line('v') }) + end, { desc = "(un)stage hunk" }) + + map('v', 'hr', function() + gitsigns.reset_hunk({ vim.fn.line('.'), vim.fn.line('v') }) + end, { desc = "reset hunk" }) + + --map('n', 'hS', gitsigns.stage_buffer) + --map('n', 'hR', gitsigns.reset_buffer) + map('n', 'hp', gitsigns.preview_hunk, { desc = "preview hunk" }) + map('n', 'hi', gitsigns.preview_hunk_inline, { desc = "preview hunk inline" }) + + map('n', 'hb', function() + gitsigns.blame_line({ full = true }) + end, { desc = "blame line" }) + + map('n', 'hd', gitsigns.diffthis, { desc = "diff buffer" }) + + map('n', 'hD', function() + gitsigns.diffthis('~') + end, { desc = "diff buffer to HEAD" }) + + map('n', 'hQ', function() gitsigns.setqflist('all') end, + { desc = "set qflist with changes in all files and cwd" }) + map('n', 'hq', gitsigns.setqflist, { desc = "set qflist with changes in current buffer" }) + + -- Toggles + map('n', 'tb', gitsigns.toggle_current_line_blame, { desc = "toggle current line blame" }) + map('n', 'tw', gitsigns.toggle_word_diff, { desc = "toggle word diff" }) + + -- Text object + map({ 'o', 'x' }, 'ih', gitsigns.select_hunk, { desc = "inner hunk" }) + end +} local wk = require "which-key" wk.add({ { "g", group = "git" }, + { "h", group = "git_hunk" } }) local statusline = { @@ -141,7 +208,7 @@ local statusline = { '%{v:lua.StatuslineBranch()}', ' %{v:lua.StatuslineFilename()} ', '%{%v:lua.StatuslineReadOnly()%}', - '%m', + '%{%v:lua.StatuslineModified()%}', '%{%v:lua.StatuslineHighlight("Middle")%}', '%=', ' ', @@ -280,7 +347,7 @@ function StatuslineMode() end function SpecialBuffer() - local pattern = '\v(help|fugitive|qf|Trouble)' + local pattern = '\v(help|oil|qf|NeogitStatus)' return string.match(pattern, vim.bo.filetype) ~= nil and true or false end @@ -288,16 +355,24 @@ function StatuslineReadOnly() return SpecialBuffer() and '' or '%r' end +function StatuslineModified() + if vim.b.modifiable then + return '%m' + else + return '' + end +end + function StatuslineBranch() - local head = vim.fn.FugitiveHead() - return SpecialBuffer() ~= true and head ~= '' and fmt(' %s |', head) or '' + local head = vim.b.gitsigns_head + return SpecialBuffer() ~= true and head ~= nil and fmt(' %s |', head) or '' end function StatuslineFilename() local special_files = { ['help'] = "Help", ['qf'] = 'QuickFix', - ['fugitive'] = vim.fn.FugitiveStatusline() + ['NeogitStatus'] = vim.b.gitsigns_head } local filename = vim.fn.expand('%:t')