From 2a76c55268139eb00345d7fac1aa58f992895533 Mon Sep 17 00:00:00 2001 From: Yuan Chiu Date: Thu, 1 May 2025 10:55:58 +0800 Subject: [PATCH] nvim: gitsigns --- .../nvim/exact_lua/exact_config/lazy.lua | 2 +- .../exact_components/exact_buffer/barbar.lua | 2 +- .../exact_plugins/exact_editor/gitsigns.lua | 87 +++++++++++++++++++ 3 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 dot_config/nvim/exact_lua/exact_plugins/exact_editor/gitsigns.lua diff --git a/dot_config/nvim/exact_lua/exact_config/lazy.lua b/dot_config/nvim/exact_lua/exact_config/lazy.lua index 352326d..51a2e65 100644 --- a/dot_config/nvim/exact_lua/exact_config/lazy.lua +++ b/dot_config/nvim/exact_lua/exact_config/lazy.lua @@ -44,10 +44,10 @@ require("lazy").setup({ -- { import = "plugins.themes.github-theme" }, -- 自訂配色 -- { import = "plugins.themes.onedark" }, -- 自訂配色 + { import = "plugins.editor" }, { import = "plugins.components" }, { import = "plugins.components.buffer.barbar" }, -- 目前只有barbar處理Buffer是最好的 { import = "plugins.ui" }, - { import = "plugins.editor" }, -- 手動引入 o-plugins 資料夾中的插件 -- require("o-plugins.nvim-listchars"), diff --git a/dot_config/nvim/exact_lua/exact_plugins/exact_components/exact_buffer/barbar.lua b/dot_config/nvim/exact_lua/exact_plugins/exact_components/exact_buffer/barbar.lua index c934ff0..a07c8a6 100644 --- a/dot_config/nvim/exact_lua/exact_plugins/exact_components/exact_buffer/barbar.lua +++ b/dot_config/nvim/exact_lua/exact_plugins/exact_components/exact_buffer/barbar.lua @@ -2,7 +2,7 @@ return { {'romgrk/barbar.nvim', version = '^1.0.0', -- optional: only update when a new 1.x version is released dependencies = { - 'lewis6991/gitsigns.nvim', -- OPTIONAL: for git status + -- 'lewis6991/gitsigns.nvim', -- OPTIONAL: for git status 'nvim-tree/nvim-web-devicons', -- OPTIONAL: for file icons }, init = function() vim.g.barbar_auto_setup = false end, diff --git a/dot_config/nvim/exact_lua/exact_plugins/exact_editor/gitsigns.lua b/dot_config/nvim/exact_lua/exact_plugins/exact_editor/gitsigns.lua new file mode 100644 index 0000000..adb4569 --- /dev/null +++ b/dot_config/nvim/exact_lua/exact_plugins/exact_editor/gitsigns.lua @@ -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 = ', - ', + 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" }, "ghs", ":Gitsigns stage_hunk", "Stage Hunk") + map({ "n", "v" }, "ghr", ":Gitsigns reset_hunk", "Reset Hunk") + map("n", "ghS", gs.stage_buffer, "Stage Buffer") + map("n", "ghu", gs.undo_stage_hunk, "Undo Stage Hunk") + map("n", "ghR", gs.reset_buffer, "Reset Buffer") + map("n", "ghp", gs.preview_hunk_inline, "Preview Hunk Inline") + map("n", "ghb", function() gs.blame_line({ full = true }) end, "Blame Line") + map("n", "ghB", function() gs.blame() end, "Blame Buffer") + map("n", "ghd", gs.diffthis, "Diff This") + map("n", "ghD", function() gs.diffthis("~") end, "Diff This ~") + map({ "o", "x" }, "ih", ":Gitsigns select_hunk", "GitSigns Select Hunk") + end, + }, +}