nvim: gitsigns

This commit is contained in:
Yuan Chiu 2025-05-01 10:55:58 +08:00
parent 411722360d
commit 2a76c55268
3 changed files with 89 additions and 2 deletions

View File

@ -44,10 +44,10 @@ require("lazy").setup({
-- { import = "plugins.themes.github-theme" }, -- 自訂配色 -- { import = "plugins.themes.github-theme" }, -- 自訂配色
-- { import = "plugins.themes.onedark" }, -- 自訂配色 -- { import = "plugins.themes.onedark" }, -- 自訂配色
{ import = "plugins.editor" },
{ import = "plugins.components" }, { import = "plugins.components" },
{ import = "plugins.components.buffer.barbar" }, -- 目前只有barbar處理Buffer是最好的 { import = "plugins.components.buffer.barbar" }, -- 目前只有barbar處理Buffer是最好的
{ import = "plugins.ui" }, { import = "plugins.ui" },
{ import = "plugins.editor" },
-- 手動引入 o-plugins 資料夾中的插件 -- 手動引入 o-plugins 資料夾中的插件
-- require("o-plugins.nvim-listchars"), -- require("o-plugins.nvim-listchars"),

View File

@ -2,7 +2,7 @@ return {
{'romgrk/barbar.nvim', {'romgrk/barbar.nvim',
version = '^1.0.0', -- optional: only update when a new 1.x version is released version = '^1.0.0', -- optional: only update when a new 1.x version is released
dependencies = { dependencies = {
'lewis6991/gitsigns.nvim', -- OPTIONAL: for git status -- 'lewis6991/gitsigns.nvim', -- OPTIONAL: for git status
'nvim-tree/nvim-web-devicons', -- OPTIONAL: for file icons 'nvim-tree/nvim-web-devicons', -- OPTIONAL: for file icons
}, },
init = function() vim.g.barbar_auto_setup = false end, init = function() vim.g.barbar_auto_setup = false end,

View File

@ -0,0 +1,87 @@
return {
"lewis6991/gitsigns.nvim",
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 = "" },
},
signs_staged_enable = true,
signcolumn = true, -- Toggle with `:Gitsigns toggle_signs`
numhl = false, -- Toggle with `:Gitsigns toggle_numhl`
linehl = false, -- Toggle with `:Gitsigns toggle_linehl`
word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff`
watch_gitdir = {
follow_files = true
},
auto_attach = true,
attach_to_untracked = false,
current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame`
current_line_blame_opts = {
virt_text = true,
virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align'
delay = 1000,
ignore_whitespace = false,
virt_text_priority = 100,
use_focus = true,
},
current_line_blame_formatter = '<author>, <author_time:%R> - <summary>',
sign_priority = 6,
update_debounce = 100,
status_formatter = nil, -- Use default
max_file_length = 40000, -- Disable if file is longer than this (in lines)
preview_config = {
-- Options passed to nvim_open_win
style = 'minimal',
relative = 'cursor',
row = 0,
col = 1
},
on_attach = function(buffer)
local gs = package.loaded.gitsigns
local function map(mode, l, r, desc)
vim.keymap.set(mode, l, r, { buffer = buffer, desc = desc })
end
-- stylua: ignore start
map("n", "]h", function()
if vim.wo.diff then
vim.cmd.normal({ "]c", bang = true })
else
gs.nav_hunk("next")
end
end, "Next Hunk")
map("n", "[h", function()
if vim.wo.diff then
vim.cmd.normal({ "[c", bang = true })
else
gs.nav_hunk("prev")
end
end, "Prev Hunk")
map("n", "]H", function() gs.nav_hunk("last") end, "Last Hunk")
map("n", "[H", function() gs.nav_hunk("first") end, "First Hunk")
map({ "n", "v" }, "<leader>ghs", ":Gitsigns stage_hunk<CR>", "Stage Hunk")
map({ "n", "v" }, "<leader>ghr", ":Gitsigns reset_hunk<CR>", "Reset Hunk")
map("n", "<leader>ghS", gs.stage_buffer, "Stage Buffer")
map("n", "<leader>ghu", gs.undo_stage_hunk, "Undo Stage Hunk")
map("n", "<leader>ghR", gs.reset_buffer, "Reset Buffer")
map("n", "<leader>ghp", gs.preview_hunk_inline, "Preview Hunk Inline")
map("n", "<leader>ghb", function() gs.blame_line({ full = true }) end, "Blame Line")
map("n", "<leader>ghB", function() gs.blame() end, "Blame Buffer")
map("n", "<leader>ghd", gs.diffthis, "Diff This")
map("n", "<leader>ghD", function() gs.diffthis("~") end, "Diff This ~")
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>", "GitSigns Select Hunk")
end,
},
}