20

I was reading the the documentation for Yasnippet mode, when I came to the section where the trigger key is defined:

It seems like Yasnippet minor mode defines the TAB key to run yas-expand using:

(define-key yas-minor-mode-map (kbd "<tab>") 'yas-expand)
(define-key yas-minor-mode-map (kbd "TAB") 'yas-expand)

What is the difference between <tab> and TAB? (I tried to google this but I could not find a clear description)

1 Answer 1

17

Although Emacs usually translates <tab> (the single key) to TAB (C-i), you can bind <tab> and TAB to different things:

(global-set-key (kbd "<tab>") #'proced)
(global-set-key (kbd "TAB") #'indent-for-tab-command)
6
  • 3
    I see, but why do Yasnippet need to define both <tab> and TAB? Feb 27, 2015 at 9:48
  • 4
    @HåkonHægland if you happen to bind them to different commands on the global-map, emacs stops translating one to the other (even on minor mode maps), so yasnippet bind both just in case.
    – Malabarba
    Feb 27, 2015 at 10:14
  • 1
    @Malabarba So if you define both <tab> and TAB, the only way to run the command associated with TAB is to type C-i ? Feb 27, 2015 at 10:38
  • 3
    If you bind <tab> to a different command than what you bind TAB to, then what you get when you hit the "Tab" key depends on which/what it sends to Emacs. If it sends C-i (aka TAB) then you get the TAB binding. If it sends <tab> then you get its binding. (And yes, you can always hit C-i to get the TAB binding.)
    – Drew
    Feb 27, 2015 at 15:57
  • 4
    More historical information about the different TAB keys are given by StreakyCobra in this spacemacs github issue. You may want to include some of that information in your answer. Oct 28, 2016 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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