better git

This commit is contained in:
Casper V. Kristensen 2024-08-18 18:12:59 +02:00
parent 1661e9769e
commit f4888d169e
2 changed files with 65 additions and 17 deletions

View file

@ -19,6 +19,7 @@
}; };
extraConfig = { extraConfig = {
diff.algorithm = "histogram";
diff.colorMoved = "default"; diff.colorMoved = "default";
init.defaultBranch = "master"; init.defaultBranch = "master";
pull.rebase = true; pull.rebase = true;

View file

@ -74,7 +74,7 @@
vim.opt.listchars = { tab=" ", trail="·", nbsp="" } vim.opt.listchars = { tab=" ", trail="·", nbsp="" }
-- Better diffs -- Better diffs
vim.opt.diffopt:append({"linematch:60", "algorithm:patience"}) vim.opt.diffopt:append({"linematch:60", "algorithm:histogram", "indent-heuristic"})
vim.opt.fillchars:append({ diff = "" }) vim.opt.fillchars:append({ diff = "" })
-- Show search-replace preview live -- Show search-replace preview live
@ -636,21 +636,6 @@
''; '';
} }
# Git integration for buffers.
# https://github.com/lewis6991/gitsigns.nvim
{
plugin = gitsigns-nvim;
type = "lua";
config =
/*
lua
*/
''
require("gitsigns").setup({})
-- TODO: keybinds
'';
}
# An interactive and powerful Git interface for Neovim, inspired by # An interactive and powerful Git interface for Neovim, inspired by
# Magit. # Magit.
# https://github.com/NeogitOrg/neogit # https://github.com/NeogitOrg/neogit
@ -662,11 +647,73 @@
lua lua
*/ */
'' ''
require("neogit").setup({}) require("neogit").setup({
graph_style = "unicode",
})
vim.keymap.set("n", "<Leader>gg", vim.cmd.Neogit) vim.keymap.set("n", "<Leader>gg", vim.cmd.Neogit)
''; '';
} }
# Git integration for buffers.
# https://github.com/lewis6991/gitsigns.nvim
{
plugin = gitsigns-nvim;
type = "lua";
config =
/*
lua
*/
''
require("gitsigns").setup({
-- https://github.com/lewis6991/gitsigns.nvim?tab=readme-ov-file#keymaps
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)
map("n", "[c", function()
if vim.wo.diff then
vim.cmd.normal({"[c", bang = true})
else
gitsigns.nav_hunk("prev")
end
end)
-- Actions
map("n", "<leader>hs", gitsigns.stage_hunk)
map("n", "<leader>hr", gitsigns.reset_hunk)
map("v", "<leader>hs", function() gitsigns.stage_hunk {vim.fn.line("."), vim.fn.line("v")} end)
map("v", "<leader>hr", function() gitsigns.reset_hunk {vim.fn.line("."), vim.fn.line("v")} end)
map("n", "<leader>hS", gitsigns.stage_buffer)
map("n", "<leader>hu", gitsigns.undo_stage_hunk)
map("n", "<leader>hR", gitsigns.reset_buffer)
map("n", "<leader>hp", gitsigns.preview_hunk)
map("n", "<leader>hb", function() gitsigns.blame_line{full=true} end)
map("n", "<leader>tb", gitsigns.toggle_current_line_blame)
map("n", "<leader>hd", gitsigns.diffthis)
map("n", "<leader>hD", function() gitsigns.diffthis("~") end)
map("n", "<leader>td", gitsigns.toggle_deleted)
-- Text object
map({"o", "x"}, "ih", ":<C-U>Gitsigns select_hunk<CR>")
end
})
'';
}
# Single tabpage interface for easily cycling through diffs for all # Single tabpage interface for easily cycling through diffs for all
# modified files for any git rev. # modified files for any git rev.
# https://github.com/sindrets/diffview.nvim # https://github.com/sindrets/diffview.nvim