1

Is there a way to map Shift-left or other arrow keys to custom functions in term-char-mode?

I tried, but without luck:

(define-key term-mode-map [s-left] 'sandric/term-switch-line-mode)

Entering Shift-left in my terminal gives [1;2D, so I also tried:

(define-key term-mode-map "[1;2D" 'sandric/term-switch-line-mode)

But that also does nothing.

Basil
  • 12,019
  • 43
  • 69
sandric
  • 1,221
  • 9
  • 19
  • Related: [Problems with keybindings when using terminal](https://emacs.stackexchange.com/questions/1020/problems-with-keybindings-when-using-terminal). – Dan Nov 26 '17 at 01:52
  • @Dan Perhaps not; see [my answer](https://emacs.stackexchange.com/a/37094/15748). – Basil Nov 26 '17 at 01:55

1 Answers1

2

Is there a way to map Shift-left or other arrow keys to custom functions in term-char-mode?

There is indeed.

(define-key term-mode-map [s-left] 'sandric/term-switch-line-mode)

Two issues here:

  1. term-mode-map is the keymap used by line mode, whereas char mode uses term-raw-map.

  2. [s-left] (lowercase s) corresponds to the <Super> modifier. The <Shift> key is abbreviated as an uppercase S, as in (kbd "S-<left>") or [S-left].


So the solution to your problem is likely

(define-key term-raw-map [S-left] #'sandric/term-switch-line-mode)
Basil
  • 12,019
  • 43
  • 69