How to send <C-left> into Emacs term?
elisp, emacs, terminal
Solution
I have the following snippet in my setup file, for the exact same purpose as you: move by words on the bash prompt using C-<arrows>
(defun term-send-Cright () (interactive) (term-send-raw-string "\e[1;5C"))
(defun term-send-Cleft () (interactive) (term-send-raw-string "\e[1;5D"))
(define-key term-raw-map (kbd "C-<right>") 'term-send-Cright)
(define-key term-raw-map (kbd "C-<left>") 'term-send-Cleft)
I found the `\e[1;5C` and `\e[1;5D` codes using the following trick:
- run `cat >/dev/null` in a terminal
- type C-<left> and C-<right> and see what is echoed back in the terminal
- exit with C-d or C-c
Another way to find them would be to type in a terminal: C-vC-<left>
Problem
I use this function to send raw commands to terminal: ``` (defun raw (str) (interactive "sKey: ") (term-send-raw-string (read-kbd-macro str))) ``` But `read-kbd-macro` for `<C-left>` return `[C-left]` which is not a string. I've also try: ``` (term-send-raw-string "\C-\eOD") ``` and ``` (define-key term-raw-map (kbd "<C-left>") 'term-send-raw) ``` But those also doesn't work. How can I send C-left then?