How do I send Ctrl-; in iterm2?

How can I send Ctrl+; in iterm2 (emacs)?

There seems to be a solution here, here and here

These are close to what I want, but I am still unable to make it work.


Solution 1:

The way I make these key combinations work is to go to the Keys section of the iTerm prefs and create a shortcut for ^; that sends some escape sequence, like ^[[aa (you can replace aa with anything, but be aware that some things are mapped to actual keys). Then in your .emacs, create a keyboard shortcut for what you want it to map to, like

(global-set-key (kbd "C-[ [ a a") 'the-function-you-want-to-map-to)

Solution 2:

How to bind a key sequence to the control key in Iterm2

  1. Download the free application “Key Codes" from the app store. Install it from the link below and then open it.

  2. Hit the Ctrl+some key in this case I’ll use Ctrl+w.

    How to get the hex code

  3. The code in the red square is the code we want to send to the terminal

  4. Now map your key sequence using in iterm, preferences->Keys->+.

How to map the command to the hex code

  1. This will now map opt+←delete to Ctrl+w in the terminal, but you can use it to map any key to another one. I know Ctrl+w is a bad example for Emacs since it doesn't support Ctrl+w but you can use this methodology for Emacs compatible shortcuts.