From cc487022fac4392efc88fc0d16f56b16c9e458d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=C3=BAc=20L=C3=AA=20Kh=E1=BA=AFc?= Date: Thu, 21 Mar 2024 11:22:35 +0700 Subject: [PATCH] feat(git): unnested hunk keymaps, add toggle &find --- lua/lazyvim/config/keymaps.lua | 2 +- lua/lazyvim/plugins/editor.lua | 35 ++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/lua/lazyvim/config/keymaps.lua b/lua/lazyvim/config/keymaps.lua index e6bbc2ab..37609e83 100644 --- a/lua/lazyvim/config/keymaps.lua +++ b/lua/lazyvim/config/keymaps.lua @@ -129,7 +129,7 @@ map("n", "ub", function() Util.toggle("background", false, {"light", "da map("n", "gg", function() Util.terminal({ "lazygit" }, { cwd = Util.root.git(), esc_esc = false, ctrl_hjkl = false }) end, { desc = "Lazygit (root dir)" }) map("n", "gG", function() Util.terminal({ "lazygit" }, {esc_esc = false, ctrl_hjkl = false}) end, { desc = "Lazygit (cwd)" }) -map("n", "gf", function() +map("n", "gh", function() local git_path = vim.api.nvim_buf_get_name(0) Util.terminal({ "lazygit", "-f", vim.trim(git_path) }, { esc_esc = false, ctrl_hjkl = false }) end, { desc = "Lazygit current file history" }) diff --git a/lua/lazyvim/plugins/editor.lua b/lua/lazyvim/plugins/editor.lua index a2ba5e35..7b0a766e 100644 --- a/lua/lazyvim/plugins/editor.lua +++ b/lua/lazyvim/plugins/editor.lua @@ -153,8 +153,10 @@ return { { "fr", "Telescope oldfiles", desc = "Recent" }, { "fR", Util.telescope("oldfiles", { cwd = vim.loop.cwd() }), desc = "Recent (cwd)" }, -- git - { "gc", "Telescope git_commits", desc = "commits" }, - { "gs", "Telescope git_status", desc = "status" }, + { "gfc", "Telescope git_commits", desc = "commits" }, + { "gfs", "Telescope git_status", desc = "status" }, + { "gfb", "Telescope git_branches", desc = "branch" }, + { "gfh", "Telescope git_stash", desc = "stashs" }, -- search { 's"', "Telescope registers", desc = "Registers" }, { "sa", "Telescope autocommands", desc = "Auto Commands" }, @@ -323,7 +325,8 @@ return { ["c"] = { name = "+code" }, ["f"] = { name = "+file/find" }, ["g"] = { name = "+git" }, - ["gh"] = { name = "+hunks" }, + ["gt"] = { name = "+toggle" }, + ["gf"] = { name = "+find" }, ["q"] = { name = "+quit/session" }, ["s"] = { name = "+search" }, ["u"] = { name = "+ui" }, @@ -363,16 +366,24 @@ return { -- stylua: ignore start map("n", "]h", gs.next_hunk, "Next Hunk") map("n", "[h", gs.prev_hunk, "Prev 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", "ghd", gs.diffthis, "Diff This") - map("n", "ghD", function() gs.diffthis("~") end, "Diff This ~") + map({ "n", "v" }, "gs", ":Gitsigns stage_hunk", "Stage Hunk") + map({ "n", "v" }, "gr", ":Gitsigns reset_hunk", "Reset Hunk") + map("n", "gS", gs.stage_buffer, "Stage Buffer") + map("n", "gu", gs.undo_stage_hunk, "Undo Stage Hunk") + map("n", "gU", gs.reset_buffer_index, "Undo all Stage Hunk") + map("n", "gR", gs.reset_buffer, "Reset Buffer") + map("n", "gp", gs.preview_hunk_inline, "Preview Hunk Inline") + map("n", "gb", function() gs.blame_line({ full = true }) end, "Blame Line") + map("n", "gd", gs.diffthis, "Diff This") + map("n", "gD", function() gs.diffthis("~") end, "Diff This ~") map({ "o", "x" }, "ih", ":Gitsigns select_hunk", "GitSigns Select Hunk") + + map("n", "gtb", gs.toggle_current_line_blame, "blame virtual text") + map("n", "gtd", gs.toggle_deleted, "deleted virtual text") + map("n", "gtl", gs.toggle_linehl, "line highlight") + map("n", "gtn", gs.toggle_numhl, "line number highlight") + map("n", "gts", gs.toggle_signs, "signs column") + map("n", "gtw", gs.toggle_word_diff, "word diff") end, }, },