-1

How can I bind C-c g g to vc-git-grep ?

So far I tried

;; in scratch buffer
(global-set-key (kbd "C-c g g") 'vc-git-grep) 
;; then M-x eval-region
;; then switch to another buffer
;; C-c g g
  • for some reason safari pops up with google browser – american-ninja-warrior Nov 20 '17 at 19:36
  • You have written both C-c g g and also C-x g g, so (a) please verify that this is merely a typo in the question; and (b) assuming that is the case, you almost certainly have either C-c g or C-c g g bound in your config to a command for opening google in a web browser. Use C-h k C-c g g to find out what the binding is, and then grep your config for that. – phils Nov 20 '17 at 22:07
  • fixed typo to show as C-c g g – american-ninja-warrior Nov 20 '17 at 22:29
  • For clarity, note that C-c followed by a letter is a sequence reserved for end-users. While it's not guaranteed, it shouldn't be the case that any elisp library has bound that sequence. It should be the case that you yourself have done this -- even if unintentionally. (If it turns out to be some third-party library, raise a bug report with the guilty party, and point them at (elisp) Key Binding Conventions.) – phils Nov 20 '17 at 23:15
  • 1
    From your comment, it sounds like the OS is intercepting your keybinding to launch safari. – Dan Nov 21 '17 at 1:44
0

Quick way

You need to make C-c g a prefix key first:

(define-key global-map (kbd "C-c g") (make-sparse-keymap))

and then bind your key:

(define-key global-map (kbd "C-c g g") 'vc-git-grep)

Why do you want to create a new prefix key?

Are you going to reuse it? If yes, you should probably go the official way:

(define-prefix-command 'my-git-prefix-map)
(define-key global-map (kbd "C-c g") my-git-prefix-map)
(define-key my-git-prefix-map "g" 'vc-git-grep)

If no, then you probably want to re-use the existing vc-prefix-map (try C-x v C-h to see the existing bindings).

  • None of that is a necessity. (global-set-key (kbd "C-c g g") 'vc-git-grep) will work just fine -- provided that neither C-c nor C-c g exist already as non-prefix bindings (and assuming vc-git is loaded). – phils Nov 20 '17 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.