0

I have set TAB to flip between two windows using:-

(global-set-key (kbd "TAB") 'other-window)

This works sometimes, but not always. How should I define it?

3
  • Say what "works" means, and say when it doesn't work. And start Emacs using emacs -Q, to remove your init file from the problem space.
    – Drew
    Sep 22, 2023 at 21:38
  • It does not work in the GNU Emacs or Directory buffers.
    – balanga
    Sep 22, 2023 at 22:52
  • 1
    Not clear. Provide a recipe, please. And buffers are not windows.
    – Drew
    Sep 23, 2023 at 0:56

2 Answers 2

2

It could possibly be caused due to sometimes the key being understood as <tab> and other times as TAB.

Switch to fundamental-mode. Try,

  1. C-h k C-i: This should get you TAB.
  2. C-h k tabkey: This may get you TAB (translated from <tab>).

One way then is to,

(global-set-key (kbd "<tab>") #'other-window)
(global-set-key (kbd "TAB") #'other-window)

For the difference between TAB and <tab> read more here.

1

(global-set-key (kbd "TAB") 'other-window)

As @scribe said, with bindings containing Tab, Backspace, Escape, etc. you may get the syntax wrong so you can read more about the use of angle brackets, and the differences in general.

This works sometimes, but not always. How should I define it?

It's hard to guess if you don't provide more details but one reason why other-window may behave "work sometimes" (i.e. changing window usually but sometimes, even if another window is present, not changing to it) is because of the no-other-window window parameter: windows such as temporary side windows (e.g. output of some command) work this way - cycling through windows will ignore them. Using ignore-window-parameters can alter this behavior.

Furthermore, bindings for functions like other-window (bindings with which you cycle through buffers/windows) may at some point "stop working" because you ended up in a buffer which overrides your keybinding.

By the way, you may consider leaving TAB alone (so you can use its default behavior), and instead using a prefix like:

(keymap-global-set "M-<tab>" 'other-window)

This uses the new key binding syntax (Emacs 29) as an example but should work exactly like global-set-key

Your Answer

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

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