1
Fork 0

Set up gitsigns

This commit is contained in:
Matei Adriel 2023-11-10 17:28:14 +01:00
parent 63a97e5870
commit 18abc39e9c
No known key found for this signature in database
6 changed files with 124 additions and 10 deletions

View file

@ -221,7 +221,7 @@ The following keybinds are available only when running inside firenvim:
| \<leader>p | [P]aste imge from clipboard | clipboard-image.nvim | | \<leader>p | [P]aste imge from clipboard | clipboard-image.nvim |
| \<leader>L | [L]azy ui | lazy.nvim | | \<leader>L | [L]azy ui | lazy.nvim |
| C-h/j/k/l | Navigate panes | vim-tmux-navigator | | C-h/j/k/l | Navigate panes | vim-tmux-navigator |
| \<leader\>h | Add file to harpoon | harpoon | | \<leader\>H | Add file to harpoon | harpoon |
| C-a | Harpoon quick menu | harpoon | | C-a | Harpoon quick menu | harpoon |
| C-s q/w/e/r/a/s/d/f/z | Open harpoon file with index 0-9 | harpoon | | C-s q/w/e/r/a/s/d/f/z | Open harpoon file with index 0-9 | harpoon |
| <leader>lc | Open [l]ocal [c]argo.toml | rust-tools | | <leader>lc | Open [l]ocal [c]argo.toml | rust-tools |
@ -235,3 +235,7 @@ Iron.nvim commands rest in the `<leader>i` namespace. There is a lot of them, an
#### Magma #### Magma
Magma commands live under the namespace `<leader>M`. I barely use this plugin, so I won't document my keybinds just yet. Magma commands live under the namespace `<leader>M`. I barely use this plugin, so I won't document my keybinds just yet.
#### Gitsigns
I use a slightly modified version of the default keybinds, and I've been too lazy to document everything.

View file

@ -17,6 +17,7 @@
"formatter.nvim": { "branch": "master", "commit": "44c89f09dcc220dc2a9b056e93c3a87c86e79804" }, "formatter.nvim": { "branch": "master", "commit": "44c89f09dcc220dc2a9b056e93c3a87c86e79804" },
"github-actions-yaml.vim": { "branch": "master", "commit": "f2f16243447cea174daa6b4a9ffd3ff9213814ef" }, "github-actions-yaml.vim": { "branch": "master", "commit": "f2f16243447cea174daa6b4a9ffd3ff9213814ef" },
"gitlinker.nvim": { "branch": "master", "commit": "cc59f732f3d043b626c8702cb725c82e54d35c25" }, "gitlinker.nvim": { "branch": "master", "commit": "cc59f732f3d043b626c8702cb725c82e54d35c25" },
"gitsigns.nvim": { "branch": "main", "commit": "af0f583cd35286dd6f0e3ed52622728703237e50" },
"harpoon": { "branch": "master", "commit": "21f4c47c6803d64ddb934a5b314dcb1b8e7365dc" }, "harpoon": { "branch": "master", "commit": "21f4c47c6803d64ddb934a5b314dcb1b8e7365dc" },
"haskell-tools.nvim": { "branch": "master", "commit": "b19df600da8ef5fb4fb280815415ebd2a4228f0f" }, "haskell-tools.nvim": { "branch": "master", "commit": "b19df600da8ef5fb4fb280815415ebd2a4228f0f" },
"hydra.nvim": { "branch": "master", "commit": "3ced42c0b6a6c85583ff0f221635a7f4c1ab0dd0" }, "hydra.nvim": { "branch": "master", "commit": "3ced42c0b6a6c85583ff0f221635a7f4c1ab0dd0" },

View file

@ -0,0 +1,100 @@
local env = require("my.helpers.env")
local M = {
"lewis6991/gitsigns.nvim",
event = "BufReadPost",
cond = env.firenvim.not_active() and env.vscode.not_active(),
config = function()
require("gitsigns").setup({
on_attach = function(bufnr)
local wk = require("which-key")
local gs = package.loaded.gitsigns
-- {{{ Helpers
local function map(mode, from, to, desc, expr)
vim.keymap.set(
mode,
from,
to,
{ expr = expr, silent = true, buffer = bufnr, desc = desc }
)
end
local function exprmap(from, to, desc)
map("n", from, to, desc, true)
end
-- }}}
-- {{{ Navigation
exprmap("]c", function()
if vim.wo.diff then
return "]c"
end
vim.schedule(function()
gs.next_hunk()
end)
return "<Ignore>"
end, "Navigate to next hunk")
exprmap("[c", function()
if vim.wo.diff then
return "[c"
end
vim.schedule(function()
gs.prev_hunk()
end)
return "<Ignore>"
end, "Navigate to previous hunk")
-- }}}
-- {{{ Actions
local prefix = "<leader>h"
wk.register({
[prefix] = { name = "gitsigns" },
})
-- {{{ Normal mode
map("n", prefix .. "s", gs.stage_hunk, "[s]tage hunk")
map("n", prefix .. "r", gs.reset_hunk, "[r]eset hunk")
map("n", prefix .. "S", gs.stage_buffer, "[s]tage buffer")
map("n", prefix .. "u", gs.undo_stage_hunk, "[u]ndo hunk staging")
map("n", prefix .. "R", gs.reset_buffer, "[r]eset buffer")
map("n", prefix .. "p", gs.preview_hunk, "[p]review hunk")
map("n", prefix .. "b", function()
gs.blame_line({ full = true })
end, "[b]lame line")
map("n", prefix .. "d", gs.diffthis, "[d]iff this")
map("n", prefix .. "D", function()
gs.diffthis("~")
end, "[d]iff file (?)")
-- }}}
-- {{{ Toggles
map(
"n",
prefix .. "tb",
gs.toggle_current_line_blame,
"[t]oggle line [b]laming"
)
map("n", prefix .. "td", gs.toggle_deleted, "[t]oggle [d]eleted")
-- }}}
-- {{{ Visual
map("v", prefix .. "s", function()
gs.stage_hunk({ vim.fn.line("."), vim.fn.line("v") })
end, "stage visual hunk")
map("v", prefix .. "r", function()
gs.reset_hunk({ vim.fn.line("."), vim.fn.line("v") })
end, "reset visual hunk")
-- }}}
-- }}}
-- {{{ Text objects
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>", "Inside hunk")
-- }}}
end,
})
end,
}
return M

View file

@ -9,7 +9,7 @@ local function bindHarpoon(key, index)
end end
function M.init() function M.init()
vim.keymap.set("n", "<leader>h", function() vim.keymap.set("n", "<leader>H", function()
require("harpoon.mark").add_file() require("harpoon.mark").add_file()
end, { desc = "Add file to [h]arpoon" }) end, { desc = "Add file to [h]arpoon" })
vim.keymap.set("n", "<C-a>", function() vim.keymap.set("n", "<C-a>", function()

View file

@ -66,19 +66,19 @@ local M = {
set_jumps = true, -- whether to set jumps in the jumplist set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = { goto_next_start = {
["]f"] = "@function.outer", ["]f"] = "@function.outer",
["]c"] = "@class.outer", ["]t"] = "@class.outer",
}, },
goto_next_end = { goto_next_end = {
["]F"] = "@function.outer", ["]F"] = "@function.outer",
["]C"] = "@class.outer", ["]T"] = "@class.outer",
}, },
goto_previous_start = { goto_previous_start = {
["[f"] = "@function.outer", ["[f"] = "@function.outer",
["[c"] = "@class.outer", ["[t"] = "@class.outer",
}, },
goto_previous_end = { goto_previous_end = {
["[F"] = "@function.outer", ["[F"] = "@function.outer",
["[C"] = "@class.outer", ["[T"] = "@class.outer",
}, },
}, },
--}}} --}}}

View file

@ -52,18 +52,27 @@ config.colors.tab_bar = {
} }
-- }}} -- }}}
-- {{{ Other visual things -- {{{ Other visual things
config.window_background_opacity = 0.6; config.window_background_opacity = 0.6 -- TODO: load from nix!
-- }}} -- }}}
-- }}} -- }}}
-- {{{ Main config options -- {{{ Main config options
config.adjust_window_size_when_changing_font_size = false -- Makes it work with fixed window sizes.
config.automatically_reload_config = true config.automatically_reload_config = true
-- {{{ Fonts
config.adjust_window_size_when_changing_font_size = false -- Makes it work with fixed window sizes.
config.font_size = font_size config.font_size = font_size
config.use_fancy_tab_bar = false -- }}}
-- {{{ Tab bar
config.use_fancy_tab_bar = true
-- config.enable_tab_bar = false
config.hide_tab_bar_if_only_one_tab = true
-- }}}
-- {{{ Keycodes
config.disable_default_key_bindings = true config.disable_default_key_bindings = true
-- config.enable_kitty_keyboard = true -- Let's apps recognise more distinct keys -- config.enable_kitty_keyboard = true -- Let's apps recognise more distinct keys
config.enable_csi_u_key_encoding = true -- For some reason I need this for all keybinds to work inside neovim. config.enable_csi_u_key_encoding = true -- For some reason I need this for all keybinds to work inside neovim.
-- }}} -- }}}
-- }}}
-- {{{ Keybinds -- {{{ Keybinds
-- }}} -- }}}