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)
PartialOrder
  • 135
  • 5

2 Answers2

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.

db48x
  • 15,741
  • 1
  • 19
  • 23
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.