How can I modify the control/option/command key mappings in the IntelliJ's Emacs keymap? - macos

GNU Emacs on Mac OS X, by default, uses the control key as CTRL, and the command key as META. This drives me crazy, because my MacBook Pro contains only a single control key on the left, while I'm used to having a control key on both sides of the keyboard.
With my GNU Emacs installation, I was able to modify the variables mac-control-modifier, mac-command-modifier, and mac-option-modifier so that command acts as CTRL and option acts as META.
How can I accomplish the same thing in IntelliJ IDEA? It's easy to select "Emacs" as the keymap, but I don't see any way make a similar remapping of CTRL and META. I know I could remap these keys globally in the OS, but I don't want to do that. I also know I could go in to each and every action and individually modify them, but that seems like a poor solution.

It's may be not the easiest solution but you can open the resources.jar (/Applications/IntelliJIdea.app/lib/resources.jar on MacOS) file, locate the Keymap_Emacs.xml (in idea directory) copy and modify it.
And then you can create a new keymap in IntelliJ for updating it with the new content (~/Library/Preferences/IntelliJIdea90/keymaps on MacOS).
That way you can change all your keymap without changing each action individually.

Related

How to remap "copy" shortcut in Xcode

I am trying to tune the key bindings in Xcode (version 8)'s preference.
Most of the keybindings can be remapped without a problem, except the Copy(Edit Menu) command.
When I am trying to map the copy command to Option+W key combination, Xcode does not allow it and show warning:
Modifiers are reserved for alternates.
Is there a way to bypass this restriction? For example, are there any copy commands other than Copy(Edit Menu) that functions similarly? Or are there any hotkey script either at MacOS level or Xcode plugin level that can remap a keybinding to another?
(I am trying to map the copy command to Option-W because I have got quite used to this key from Emacs. )
Thank you.
On Mac OS, Option-W is a typable character. It cannot be a hotkey. Hotkeys must include Command or Control.

How can I use `M-x` in `emacs -nw` in zshell

It is my first time to use emacs -nw. But I have problem at the first when I type M-x. In the minibuffer, it shows "Mark set" instead of M-x
I don't know why it happens. How can I deal with it?
PS: My os is Macosx and I connect remote by using ssh and then I type emacs -nw but I cannot use M-x
Update:08/30/2015
When I see the options under M-x customize-group ns, it seems that Alt is actually used as Meta? Why it didn’t works.
14Hide Ns Alternate Modifier: [Value Menu] meta |
15 [ State ]: STANDARD. |
16 This variable describes the behavior of the alternate or option key. More |
37Hide Ns Right Alternate Modifier: [Value Menu] Use the value of ns-alternate-modifier |
38 [ State ]: STANDARD. |
39 This variable describes the behavior of the right alternate or option key. More |
When using Emacs in the terminal (switch -nw), you might not have a Meta key, depending on your platform etc. In particular, the Alt keyboard key might not function as the Meta key. You might find some information (e.g. here, or by googling) about how to get it working as Meta for your context (platform etc.), but you might not.
You can always use ESC (the Escape key) followed by a key to act the same as the Meta modifier applied to that key. For example, instead of M-x, you can use ESC x.
(You press and release ESC, and then do the same for x. ESC is not a modifier key -- you do not hold it pressed while hitting x.)
Your problem is that OSX is stealing the key. There are a few things which will make your life easier
Install emacs using homebrew. The version which comes with OSX is old
Use iterm2 instead of the default term.app - much better and feature rich
In iterm2, you can set a key override for either the left or right option as +ESC, which will make it all work.
This will all work on a local machine, but you may run into additional problems if your connecting to a remote machine and running emacs there. It is a similar problem, your key settings may no be getting stolen/dropped by the ssh session - all depends on your terminal, your ssh config and the remote system.
Note that with emacs, you often don't need to run remote. Emacs comes with a built-in system called Tramp, which is very powerful. Using tramp, you can open remote directories and edit the files as if they were local files. You run emacs locally and tramp uses ssh to open the remote files, read the contents into the local emacs buffer and then write the changes back tot he remote file. Helps to have ssh keys setup so you don't have to worry about passwords (but you will need an ssh-agent to make this work easily).
In general, when you find emads does not respond to a key press, especailly if you try C-h k and nothing happens when you hit the key bindings you can't get to work, it is almost certain that something in-between you and emacs is stealing the keys - this is often the window manager or OS, but it can also be due to terminal emulators etc. In over 20 years of using emacs, I've never had emacs 'do nothing' when you hit a key combination - if emacs recieves the key input, it will respond with something, even if that something is to tell you there is no key binding for the keys you pressed. If emacs does absolutely nothing, you know the message just isn't get through!
Open Terminal Preferences
Select Profiles
Keyboard
Check the box for "Use Option as Meta Key"

Using the ALT key on Komodo for Mac OS X

I am using the Emacs keybinding on Komodo IDE where Komodo uses the command key for "Meta" by default. So you press Command-X when you normally press Alt+X for Emacs on Linux.
I want to use the actual Alt key .. so when I tried to assign Alt+K, Komodo informs that "This key combination is not available" (see screenshot below)
Komodo Preferences Dialog screenshot http://dl.getdropbox.com/u/87045/permalinks/komodo-alt-key.png
How do I use the Alt key in Komodo? Is it possible?
On the Mac the Option/Alt key is used to quickly enter non-ASCII characters.
Komodo provides a few bindings involving control keys, like Alt+Return to
edit a file's properties, but it stays away from the Alt/Option key for
the most part.
I tried binding [Go to file...] to Cmd+Alt+K. The preferences dialog
accepted it (although it said it was first bound to Cmd+¬, and later said
it was bound to Cmd+Alt+Û, both of which gave me the feeling that
the binding would fail to work. There have been Mozilla bugs dealing
with inconsistencies in keybindings on OS X, and we're seeing that here.
Komodo will also let you create keybindings using combinations of
the Command, Control, and Shift keys -- I would stick with those,
and leave the Alt key for entering non-ASCII characters.
One can workaround this behavior using ControllerMate or a similar tool:
Create a new Driver Configuration for your normal keyboard
In that configuration, swap the Option and Command keys
Disable this new configuration
Create a new ControllerMate page
Add an Application Block to that page which only triggers when Komodo IDE is running in the foreground
Add a Properties Block connected to the Application Block which enables your Driver
Configuration.
Thus, when Komodo IDE is running in the foreground, ControllerMate swaps
Command and Option, giving you the Meta behavior you get everywhere else in OS X.

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,

Page down and page up in Emacs on Windows using the Windows key

I am trying to learn Emacs and trying to find best keyboard layout for me. One thing is really annoying me. I have added following lines to .emacs
(global-set-key "\C-y" 'scroll-up)
(global-set-key "\M-y" 'scroll-down)
When I hold Control and press y a few times, it will page down on every press of y.
However, when I hold the Windows key (mapped as Meta) and press y a few times it will only page up on the first press of y and all subsequent presses of y I get the ‘y’ character inserted in the buffer.
Can the page up behave like page down? I want to hold Meta and keep pressing y to scroll multiple pages up.
I am using GNU Emacs 23.0.60.1 (i386-mingw-nt5.1.2600) of 2008-05-12 on LENNART-69DE564 (patched). It is Emacs with EmacsW32 patch. Is this problem with this Emacs? Problem with Meta key?
I tried original GNU Emacs (not patched) and it works OK with Alt. But my problem is not that I want to scroll without releasing any key. I release key y and press it multiple times but don't want to have to release Meta key. Same problem is described here:
http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/f30f4b75a8b75b10
Problem is not in that I have changed key mapping. It looks like it is a bug in EmacsW32 version. Here is another description of the problem:
Unreleased Meta/Win modifier
Use C-v and M-v.
Don't change C-y, M-y default bindings.
Could this be a side affect of using the Windows key as Meta? I'm thinking this because in a non-Emacs situation if you press and hold the Windows key and another key for a short cut (Win+E for Explorer, Win+R for Run dialog, etc.) the desired action only triggers once, not multiple times if you keep holding it down.
I'd try reassigning Meta to Alt and see if the problem persists. If it doesn't, then I'm not sure what other option you have, since likely it's the OS only sending the Windows key press once to the app in focus.
You should use the patched EmacsW32 version, if you want the Windows key as Meta.
From the site about the patches:
"Changes that makes it possible to use the window keyboard keys as META in Emacs. Without this patch key sequences like E will always do what they by default does in windows, ie in this case open up Windows Explorer. (This patched is not used by default, you have to turn it on.)"

Resources