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)

Håkon Hægland
  • 3,608
  • 1
  • 20
  • 51

1 Answers1

16

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)
abo-abo
  • 13,943
  • 1
  • 29
  • 43
  • 3
    I see, but why do Yasnippet need to define both `` and `TAB`? – Håkon Hægland Feb 27 '15 at 09: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 '15 at 10:14
  • 1
    @Malabarba So if you define both `` and `TAB`, the only way to run the command associated with `TAB` is to type `C-i` ? – Håkon Hægland Feb 27 '15 at 10:38
  • 3
    If you bind `` 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 `` then you get its binding. (And yes, you can always hit `C-i` to get the `TAB` binding.) – Drew Feb 27 '15 at 15:57
  • 4
    More historical information about the different `TAB` keys are given by `StreakyCobra` in [this](https://github.com/syl20bnr/spacemacs/issues/4024) spacemacs github issue. You may want to include some of that information in your answer. – Håkon Hægland Oct 28 '16 at 09:16
  • 1
    Thanks @HåkonHægland, [this comment](https://github.com/syl20bnr/spacemacs/issues/4024#issuecomment-161122099) in that issue was the level of detail I was looking for! So if you want the binding to work for both GUI and terminal, use `TAB`, or if GUI-only, use ``. – Adam Spiers Jun 30 '20 at 12:10