Emacs arrow keys not working (producing [A], [B], etc instead)
If when running Emacs in a terminal, you are getting [B] when hitting the down arrow, instead of the cursor moving down [A] when hitting the up arrow, [D] when hitting left and [C] when pressing right, you may be tempted to think the terminal is at fault.
You could indeed potentially fix it by changing the $TERM environment variable to “xterm”, and “tricking” the terminal into thinking it is something that it is not. This is not a good idea, as it may cause other issues elsewhere.
This issue can be caused by improper key bindings set in Emacs.
(global-set-key (kbd "M-[") 'insert-pair) [B [B]]
The above keybinding which worked for older versions of Emacs, caused the problem in Emacs version 30.1.
Also check other keybindings. Note the “\C-cx” depiction of the keybinding. For example…
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-cc" 'org-capture)
(global-set-key "\C-ca" 'org-agenda)
Use the ‘ kbd ’ function to convert the keys to the internal Emacs key representation. This might also be a source of issues.
(global-set-key (kbd "C-c l") 'org-store-link)
(global-set-key (kbd "C-c c") 'org-capture)
(global-set-key (kbd "C-c a") 'org-agenda)