22

I'd like to bind Ctrl + R to 'isearch-backward and bind Ctrl + Shift + R to 'tags-apropos but I can't distinguish between the two key presses.

Can emacs differentiate between Ctrl + R and Ctrl + Shift + R? What should go into my .emacs file to allow this keybinding?

Jasper
  • 2,166
  • 4
  • 30
  • 50
Alex B
  • 24,678
  • 14
  • 64
  • 87

2 Answers2

35

Yes.

(global-set-key (kbd "C-r") 'isearch-backward)
(global-set-key (kbd "C-S-r") 'tags-apropos)

The way to figure out the answer to this kind of question is to do help on a key C-h k, and type the keystrokes you're interested in. What Emacs shows in the Help buffer is the string you can pass to the macro 'kbd.

Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
2

Yes -- one is "\C-r", the other is "\C-R". They can easily be bound to separate commands. For example, this should do the trick if placed in your .emacs file:

(global-set-key "\C-R" 'tags-apropos)
Adam Rosenfield
  • 390,455
  • 97
  • 512
  • 589
  • 2
    Unfortunately, that doesn't work. When you pass a string to global-set-key, any uppercase character gets translated to its lowercase equivalent. So (global-set-key "\C-R" 'tags-apropos) will actually bind Ctrl + r, not Ctrl + Shift + r. To work around this translation, you can use the 'kbd macro, as the other answer states. – Tim Lesher Jul 16 '12 at 15:10