Why can't emacs on OSX in iTerm2 not see C-S-<up>? - macos

I have the following keyboard shortcut in my init.el
(global-set-key (kbd "C-S-<up>") 'move-line-up)
This works great in Cocoa Emacs.app, but when running emacs in console mode in iTerm2 it seems that they keys never make it to emacs.
I tried running the following in emacs
(read-key-sequence "?")
And entering C-S-<up> in the prompt but it was never received. That makes me think that either iTerm2 or zsh is stealing the keystrokes. Any ideas on how to debug this? Or better yet answers?

My guess would be that it's iTerm intercepting things.
You might find this site helpful. It says:
Select Profiles > Open Profiles… from the menu bar, or press Command-O and take a look at the default profile. Click on the Keys section. While you are here verify you have Left Option and Right Option as +Esc.
For the arrow key fixes though you will need to add a series of key shortcuts. The easiest way to get started is select Load Preset… > xterm Defaults

Related

CMD-Period unexpectedly translated to ESC in IDEA apps on macos (PyCharm, GoLand, Android Studio)

I use Cmd-. (Command-Period) as a common hotkey in my IDEs (go to definition), but recently the IDEA/JetBrains IDEs have started to re-interpret this key combination as the escape key. I can't figure out what exactly changed on my system to make this start happening. There was probably an OSX update or two which happened between the last time it worked and when I noticed the new behavior.
In the IDEA keymap menus, when I hit Cmd-. in the search-by-key dialog, it inserts the Esc glyph, the the behavior of the rest of the app seems to follow suit, it's just acting like Esc.
This issue seems to be specific to the IDEA-based apps. It reproduces in PyCharm, GoLand, and Android Studio. Cmd-. still works as expected in iTerm2, Cocoa Emacs, and the OSX system shortcut settings window.
Any idea of how I can bring back Cmd-., or at least interpret it as something other than Esc?
Unfortunately, there's no way to stop interpreting Cmd-. as Esc. However, as a workaround, you can try assigning the shortcut in a keymap XML file.
It may help in some cases, e.g. it works for opening tool windows, but it doesn’t work with Find in Path because sometimes the dialog gets closed (both meta . and Esc are invoked).
In Preferences | Keymap, set some shortcut to the desired action, and exit IDE
Open settings directory: https://intellij-support.jetbrains.com/hc/en-us/articles/206544519
Open a keymap XML file under "keymap" directory
Find the action changed in step 1, and change the "first-keystroke" parameter of the "keyboard-shortcut" node to "meta period". So it will look like:
<keyboard-shortcut first-keystroke="meta period" />

emacs control D key binding overridden

Any solutions out there for dealing with google script code-editor turning "forward delete" into a "kill line" binding? I'm used to the hidden cocoa/emacs derived navigation keys. Google decided to mess with control-d.
Clarifications:
This occurs when using the code editor. (edit-view?)
I would rather stop the google behavior than cope with it.
To understand more how fluid the control-key navigation can be
(and therefore how annoying when missing), try this...
set caps-lock to be the control key
open a cocoa browser like Safari and
start a script at https://script.google.com/
switch briefly to address bar
hit ctrl+a (goes to start of line)
hit ctrl+d (characters get deleted 1 at a time)
hit escape
switch to script area and try same thing (whole lines get munched!)
If you mean while you're working on your program in that editor, press the forward-delete key. On Apple's laptops and wireless keyboard, it's fn-delete (where by “delete”, I mean the backward delete, the key that is a.k.a. “backspace”).
You could try KeyRemap4Macbook.
Today I noticed that this problem no longer exists. So when editing a script file in the macro editor, emacs shortcuts WORK as expected. I cannot tell if they simply removed a bug or override, or actually patched it to work.

iTerm Emacs key codes for Ctrl + <Arrow Keys>

In Emacs on Linux terms and Cygwin, Ctrl + Up/Down causes a long jump (depending on the mode) say one function block down, on iTerm however this does not work I am assuming I need to manually set key codes send?
I guess you are using iTerm 2. Go to Preferences window in iTerm, and check both "Keys" tabs. One is in the main tabs and the second is for each profile. By default, in the "Keys" tab in your profile ^↑ are ^↓ are defined there to send some backward-compatible special keys. Remove them for your profile and you're good to go!
UPDATE: This change doesn't seem to affect your current tab or window. You may need to start a new iTerm window.
Use M-{ and M-} instead.

Why is my Ctrl-key disabled in iTerm.app?

I'm trying to use the new iTerm app on my Snow Leopard Mac, but my Ctrl seems to be completely dead (as in non-responsive, as in nothing happens when I type Ctrl+a except for an outputed 'a') and I haven't found anything useful while googling. The closest match was this thread here on stackoverflow, but everything in Terminal.app works as it should.
And, even more strange - I can Ctrl+z myself out of applications, but I can't save files in Emacs (C-x C-s) or any other keyboard shortcuts that uses a Ctrl shortcut. And it's not local, since Ctrl is as broken on my iMac as it is on other unix computers I've sshed onto with iTerm. I've tried both in bash and zsh.
I've tried to remove all files concerning iTerm.app in my ~/Library/Application Support, and I've tried the very latest version (currently 13 h old) of iTerm I could lay my hands on, but to no avail.
Any ideas?
This seems to be an iTerm bug.
You can work around it by creating a key mapping in the profile settings.
Add a mapping for ^x so it sends 0x18 (which is the encoded form of ctrl+x).
I suggest to check this post to see if the ctrl key is enabled in your preferences
https://apple.stackexchange.com/questions/52041/how-to-press-control-key-on-mac
Did you try to configure key bindings for this terminal emulator as specified in the iTerm wiki:
http://code.google.com/p/iterm2/wiki/Keybindings
at last, have you try set -o emacs or set -o vi?
If it works, set it in your ~/.bashrc to run it at login.

Making iTerm to translate 'meta-key' in the same way as in other OSes

In bash shell with emacs key-binding, you can use key combination like M-f, M-b to move one word forward or backward on the shell prompt respectively. Usually, the meta key is mapped to Alt key on Windows and Linux. However, in iTerm, I could not find a way to map this meta key to either Option or Command key on my MacBook Pro.
It seems that in OS X, the meta key is by default mapped to ESC key. So you can use ESC-f, ESC-b on iTerm. However, ESC key is apparently not practical to use. In addition, iTerm does have option that allow you to modifier mapping for the meta key (Bookmarks > Profiles > Keyboard Profiles > Global > Option Key as...), this setting does not seem to work at all.
Therefore, if anyone know what is the solution to this problem, please let me know.
I have upgraded to the latest release, 0.9.6.1012, and this behavior is still persist.
Edit: Some clarification to my question. The key-binding I'm talking about is for bash shell, not in emacs. It just happens that, by default, bash shell also use the same key-binding as emacs.
Open "Preferences" (⌘,) -> Profiles -> Keys -> General tab.
Set Left Option key: to act as Esc+.
Works for me in Emacs, though I'm not sure if it will have any other undesirable effects.
Go to Bookmarks > Manage Profiles. Then select Keyboard Profiles > Global and choose Option Key as Meta. This works for me in version 0.9.6.1201.
In Menu bar Iterm2 => Preferences => Profiles choose the keys tab and select
left Option key act as +Esc
worked for me as well in irssi.
For iTerm2 users this answer just partially solves the problem.
Cmd+., Profiles, Keys and choose Left option Key acts as: +Esc.
In addition to that, you have to go to Preferences (Cmd+,) ➔ Profiles ➔ Keys and in the Key Mappings find these Key Combination's: and . Double click on each mapping and change their Action and Esc+ to the following:
Go to your iTerm preferences select "profiles" then "key" and change your presets in "Natural Text Editing"
It should work immediately after.
It works with iTerm version 3.3.12
Going all zombie resurrection here, but for sake of posterity --
This post got it working as you desire for me, for M-b and M-f, while keeping 'Option Key as Meta' set so you don't sacrifice a modifier (I have vim mappings using meta, personally).
In summary, in your Global Keyboard Profile, add two new mappings with settings:
Key as hex code, value of 62 for b, 66 for f (man ascii)
Modifier as Option
Action as send escape sequence, value b or f
The only thing I still miss from Terminal.app is Opt-Backspace to delete by word. There are other workarounds for that, but I'm just trying to train myself to use Ctrl-w.
It's easier in iTerm2. Go to preferences->bookmark->keyboard and select Option sends +ESC. In iTerm2 you can configure the left and right option keys separately, so remember to change both if that's what you want. Link for iTerm2: http://sites.google.com/site/iterm2home/
Go to Bookmarks > Manage Profiles. Then select Keyboard Profiles > Global and choose Option Key as +ESC.
Works in iTerm Build 0.9.5.0611 & Build 0.9.6.20090415
I found some solution on stackoverflow also, just go to keyboard profile and in "Global" change "Option key as" +ESC
that works for me perfectly =) btw some iterm patch exists also look here: http://www.emacswiki.org/emacs/EmacsForMacOS
I don't know about iTerm, but you can do this in Terminal. Instructions can be found here:
Emacs on Mac OS X Leopard key bindings
Here is what worked for me: Bookmarks > Manage Profiles > Keyboard Profiles > Global/xterm > Option Key as +Esc. With this, I can use Option+Enter in Midnight Commander and the currently selected file/directory name shows up in the command string, as it should. Option Key as Meta did not work for me. My build of iTerm is 0.10.
I was struggling with Meta + Left or Meta + Right. The context was for keystroke in Emacs utilized in an iTerm2 session.
I tried Esc+ and Meta for the left Option key with no luck. I tried with and with out the hex mappings. No luck.
But then I tried "Report modifiers using CSI u". (Documentation here). That allowed me to use the meta + Left and meta + right keys in Emacs, which is the behavior I have on my Linux machine.
The common answers of setting the options key to ESC+, didn't work for me out of the box. At some point I realized that it doesn't work only when opening the floating iterm terminal (using F12). The trick to fix it was setting the options key to ESC+ also for the "Hotkey Window" profile.
This tiny note in the "Apps can change this" mouseover made all the difference for me:
After trying all the options above for what seemed like hours, it was as simple as setting the "Right Option key" to act as Esc+ (though I was pressing Left).
Try "export LANG=C". I'm not emacs expert, but I found this enables emacs on OS X to recognize the Option key as the Meta key in iTerm,

Resources