Skip to main content
3 of 5
Edit answer in response to the comments
dalanicolai
  • 8.1k
  • 9
  • 25

EDIT

To bind a command directly in the magit-status-mode-map, bind it as follows using define-key:

(define-key magit-status-mode-map "G" 'counsel-projectile-rg) 

I have bound it under G as g is used as a prefix command in the magit-status buffer.

END EDIT

You can add a transient suffix with the following line of code:

(transient-insert-suffix 'magit-dispatch (kbd "h") '("G" "grep" counsel-projectile-rg)) 

read the docstring of transient-insert-suffix for an explanation. There is also the command transient-append-suffix which works similarly.

Here I am adding the command counsel-projectile-rg, which I use myself for this case (well actually I am just using the Spacemacs key-sequence SPC /), and which I can really recommend. There are equally good alternatives for helm, consult and probably more... also for other backends like grep, ag etc...

dalanicolai
  • 8.1k
  • 9
  • 25