Problem:Using Systems:Ubuntu 16.04, xterm, emacs-nox
I want to bind the keys Ctrl+iCtrl+mCtrl+[ and Meta+Shift+o to any command I want.
But the problem seems to be that all of said key sequences are bound to:
Tab, Return, Escape, and Control Code ESC 0 respectively becuase that's just the way terminals work.

So how do I keep the functionality of the Tab, Return, and Escape whilst having said keybinds at my disposal?
Do I have to remap the keys in the terminal somehow? If so, how?
I will do anything to make this work.

where ^[ needs to be replaced by the escape character, entered (in emacs) with C-q ESC (C-q runs quoted-insert which inserts the next character literally). The actual escape character can't be displayed in the browser, so I'm using the string ^[ to represent it, as that's how it's typically displayed. \n\ is needed at the end of each line that is continued.

^[OJ and ^[OK were chosen as these sequences seemed to be free. (You can determine which sequences are "free" by inspecting input-decode-map within Emacs, via C-h v input-decode-map RET. The map is effectively a "tree". The numerical values are the codes of the corresponding characters — for instance O is 79. You can determine the code of the letter O by evaluating ?O etc.)

It's not working for me :/ A couple things are happening: 1) When I did xrdb -load .Xresources and restarted my xterm it like inverted my colors making the background white and text black (I haven't changed the default colors of the terminal); and made strings (in between " ") invisible within emacs. 2) When I did (define-key key-translation-map (kbd "^[OJ") 'previous-line) all emacs does is spit out the string "^[OJ in the buffer.
– John DeBordApr 7 '18 at 5:22

Update: The first issue seems to be unrelated; when I log out and log back in the terminal colors are back to normal.
– John DeBordApr 7 '18 at 5:38

1

Update: When I describe the key in emacs using Ctrl-h k for Ctrl-i the description is: ^ runs the command self-insert-command, which is an interactive built-in function in 'C source code'. It is bound to many ordinary text characters. Not sure if this is a clue or not.
– John DeBordApr 7 '18 at 6:51

1

Yes, any number other than those taken could be used. Regarding the "<>" syntax, it seems after testing (but I can't easily find anything in the documentation), that you can use an arbitrary string (even "<abcdefgh>") — so you could just use the non-standard, but descriptive "<control_i>" etc. It appears to work and I don't think it would break anything. (One issue that might come up in the future is if you start using a terminal emulator other than xterm — since they have different translation maps — but it's independent of the choice of the "<>" key names.)
– aplaiceApr 8 '18 at 8:30

1

Regarding interpreting the translated bindings in bash — I don't think there's any simple solution. You could try to use the bind bash command (e.g. bind '"\eOJ": ""' where \e is the escape character (yes, different conventions in different programs, for the same character, are annoying...) and "" is deliberately the empty string — see the info manual for details), but things are likely to start getting very brittle. As for moving the conversation to chat, I'm not certain how to do that.
– aplaiceApr 11 '18 at 13:33