Skip to content

Commit efa5b5c

Browse files
committed
feat(nvim): remap yanking cmd, add hunk_preview
1 parent 02e188f commit efa5b5c

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

nvim/lua/config/autocommands.lua

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
local utils = require "utils"
2-
31
vim.api.nvim_create_augroup("Highlight", { clear = true })
42
vim.api.nvim_create_autocmd("TextYankPost", {
53
command = "silent! lua vim.highlight.on_yank({higroup='IncSearch', timeout=1500, on_visual = true})",

nvim/lua/config/mappings.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ vim.keymap.set("n", "<F3>", function()
107107
}
108108
end, { noremap = true, silent = true })
109109

110-
vim.keymap.set("n", "<Space>fn", function()
110+
vim.keymap.set("n", "<Space>yn", function()
111111
local filename = vim.fn.expand "%:p"
112112
utils.info("Yanking current filename: " .. filename, "INFO")
113113
vim.fn.setreg("+", filename)
@@ -122,7 +122,7 @@ local function yank_nodepath()
122122
end
123123
end
124124

125-
vim.keymap.set("n", "<Space>fp", function()
125+
vim.keymap.set("n", "<Space>yp", function()
126126
local path = yank_nodepath()
127127
print(path)
128128
utils.info("Yanking current " .. vim.bo.ft .. "path: " .. path, "INFO")

nvim/lua/config/options.lua

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
vim.g.mapleader = " "
2+
vim.g.localleader = " "
23

34
local globals = {
45
-- Fix vim sandwitch overriding sentence text object

nvim/lua/plugins/gitsigns.lua

+29
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,35 @@ return {
1313
delay = 100,
1414
},
1515
current_line_blame_formatter = " <abbrev_sha> | <author>, <author_time> - <summary>",
16+
on_attach = function(bufnr)
17+
vim.keymap.set(
18+
"n",
19+
"<leader>hp",
20+
require("gitsigns").preview_hunk,
21+
{ buffer = bufnr, desc = "Preview git hunk" }
22+
)
23+
24+
-- don't override the built-in and fugitive keymaps
25+
local gs = package.loaded.gitsigns
26+
vim.keymap.set({ "n", "v" }, "]c", function()
27+
if vim.wo.diff then
28+
return "]c"
29+
end
30+
vim.schedule(function()
31+
gs.next_hunk()
32+
end)
33+
return "<Ignore>"
34+
end, { expr = true, buffer = bufnr, desc = "Jump to next hunk" })
35+
vim.keymap.set({ "n", "v" }, "[c", function()
36+
if vim.wo.diff then
37+
return "[c"
38+
end
39+
vim.schedule(function()
40+
gs.prev_hunk()
41+
end)
42+
return "<Ignore>"
43+
end, { expr = true, buffer = bufnr, desc = "Jump to previous hunk" })
44+
end,
1645
worktrees = {
1746
{
1847
toplevel = vim.env.HOME,

0 commit comments

Comments
 (0)