1

GNU Emacs 27.2 in Mac OS terminal (11.4 Big Sur).

Started with

(windmove-default-keybindings)  

and found that S-<up> and S-<down> behaved just as <up> and <down>, as if the shift is not detected, whereas S-<left> and S-<right> behaved as expected.

Tried

(define-key global-map (kbd "S-<up>") 'windmove-up)
(define-key global-map (kbd "S-<down>") 'windmove-down)

and there was no change in behavior.

Saw this: Windmove-mode: S-up and S-down becomes text selection instead of switching windows and tried adding

(setq shift-select-mode nil)

(even though S-<up> and S-<down> were not acting to select), and again, no change in behavior. windmove works correctly with S-<up> and S-<down>, but not for S-<left> and S-<right>.

Complete, minimal .emacs file:

; (windmove-default-keybindings)
(define-key global-map (kbd "S-<up>") 'windmove-up)
(define-key global-map (kbd "S-<down>") 'windmove-down)
(define-key global-map (kbd "S-<left>") 'windmove-left)
(define-key global-map (kbd "S-<right>") 'windmove-right)

(setq inhibit-startup-message t)
(load-theme 'wombat)
(menu-bar-mode -1)
2
  • Use iterm2 not the default terminal program. Jul 28, 2022 at 17:53
  • @FranklinHerman The default terminal is configurable as well, with a very similar interface. iTerm2 is almost identical in this respect, its only advantage is that it knows a few more key chords by default. Jul 28, 2022 at 21:45

2 Answers 2

0

Programs running in the terminal can’t receive a lot of key combinations. Shifted arrow keys are just one more example in a long list. Run the Emacs gui instead.

You can see this in action by using C-h k, then pressing a key combination. Emacs will tell you what it received and what command it would invoke.

1
  • That depends on the terminal. The macOS Terminal application doesn't distinguish Shift+{Up,Down} from {Up,Down} by default, but it can easily made to. Jul 28, 2022 at 21:47
0

Terminal emulators (and hardware terminals) send escape sequences for key chords involving cursor keys or function keys. Only a few key chords have widely accepted standard escape sequences, and many terminals ignore certain modifiers. In particular, the macOS Terminal application sends the same escape sequence for Shift+Up as for Up, so Emacs has no way to distinguish between the two. See Shift+Up isn't recognized by Emacs in a terminal and Problems with keybindings when using terminal for more background.

You can change escape sequences in the Terminal preferences, under the “Keyboard” tab of each profile. Choose Up as the key, Shift as the modifier combination, “Send Text:” as the action and \033[1;2A as the text. (\033 stands for an escape character, which can also be shown as ESC or ^[ in other contexts.) This is a standard encoding of Shift+Up which Emacs recognizes out of the box. For Shift+Down, use \033[1;2B as the text. If you want other modifier combinations, use 1;5 for Ctrl and 1;6 for Ctrl+Shift. Left is C and Right is D. Terminal supports {Shift,Ctrl}+{Left,Right} out of the box.

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.