How can I map `git next-hunk` to a key?

I’d like to git gd to jump to the next diff. I imagine I could do something like this:

map global goto d ': git next-hunk<ret>`

But that doesn’t seem to work. I just get an error that says “No search pattern”. When I try : echo something as the binding instead, I get ho something\n inserted into my buffer, so I suspect the leading colon doesn’t do what I want in goto mode. Any ideas?

(BTW I’m not sure why I need the space after the colon but I’ve seen it in some examples in plugin repos… I’d love to know if someone can tell me why that’s necessary!)

The space after the colon (": ") is to avoid having your custom command (“git next-hunk”) register in Kakoune’s command history (the history you can call in command mode by typing Ctrl-P or using the up arrow). As far as the mapping is concerned, though, everything works the same regardless of the space.

you need to escape goto mode first, so try map global goto d '<esc>: git next-hunk<ret>

1 Like

sweet, that works perfectly. Thank you!