1
0
Fork 0

basic git support

This commit is contained in:
zymon 2024-08-27 10:30:23 +02:00
parent 833ad4dd82
commit 36a826d429
2 changed files with 64 additions and 0 deletions

View file

@ -18,6 +18,7 @@ vim.opt.number = true
vim.opt.relativenumber = false vim.opt.relativenumber = false
vim.opt.numberwidth = 5 vim.opt.numberwidth = 5
-- vim.opt.statuscolumn = "%C %4l %r" -- vim.opt.statuscolumn = "%C %4l %r"
vim.opt.signcolumn = "auto:1-2"
vim.opt.wrap = false vim.opt.wrap = false
vim.opt.breakindent = true vim.opt.breakindent = true

63
lua/znvim/plugins/git.lua Normal file
View file

@ -0,0 +1,63 @@
return {
{ -- gitsigns
"https://github.com/lewis6991/gitsigns.nvim",
event = "BufReadPre",
opts = {
signs = {
add = { text = "" },
change = { text = "" },
delete = { text = "_" },
topdelete = { text = "" },
changedelete = { text = "~" },
untracked = { text = "" },
},
signs_staged = {
add = { text = '' },
change = { text = '' },
delete = { text = '_' },
topdelete = { text = '' },
changedelete = { text = '~' },
untracked = { text = '' },
},
attach_to_untracked = true,
on_attach = function(buffer)
local gitsigns = package.loaded.gitsigns
local function map(mode, l, r, desc)
vim.keymap.set(mode, l, r, { buffer = buffer, desc = desc })
end
map("n", "]h", gitsigns.next_hunk, "next hunk")
map("n", "[h", gitsigns.prev_hunk, "prev hunk")
map("n", "<leader>gb", gitsigns.blame_line, "blame line")
map("n", "<leader>gB", function() gitsigns.blame_line({ full = true }) end, "full blame!")
map("n", "<leader>gp", gitsigns.preview_hunk, "look at hunk")
map("n", "<leader>gS", ":Gitsigns select_hunk<CR>", "select hunk")
map("n", "<leader>gd", gitsigns.diffthis, "diff this")
map("n", "<leader>gsb", gitsigns.stage_buffer, "stage buffer")
map("n", "<leader>gsh", ":Gitsigns stage_hunk<CR>", "stage hunk (toggle)")
map("v", '<leader>gsh', function()
gitsigns.stage_hunk({vim.fn.line('.'), vim.fn.line('v')})
end, "stage selected hunk")
map("n", "<leader>gsu", ":Gitsigns undo_stage_hunk<CR>", "undo last stage hunk")
map("n", "<leader>grb", "<cmd>Gitsigns reset_buffer<CR>", "reset buffer")
map("n", "<leader>grh", "<cmd>Gitsigns reset_hunk<CR>", "reset hunk")
map("v", '<leader>grh', function()
gitsigns.reset_hunk({vim.fn.line('.'), vim.fn.line('v')})
end, "reset selected hunk")
map("n", "<leader>gtl", "<cmd>Gitsigns toggle_linehl<CR>", "toggle line highlight")
map("n", "<leader>gtn", "<cmd>Gitsigns toggle_numhl<CR>", "toggle line number highlight")
map("n", "<leader>gts", "<cmd>Gitsigns toggle_signs<CR>", "toggle signs")
map("n", "<leader>gtw", "<cmd>Gitsigns toggle_word_diff<CR>", "toggle word diff")
map("n", "<leader>gtd", "<cmd>Gitsigns toggle_deleted<CR>", "toggle deleted lines")
map("n", "<leader>gtb", "<cmd>Gitsigns toggle_current_line_blame<CR>", "toggle current line blame")
end,
},
},
}