I'm trying to find a way to use only the left option key as the Meta Key in osx Terminal, but leaving the right option with it's normal functions (special characters #, #, etc.).
Is there any way to config it to work this way? (Basically i want to achieve the same functionality that iterm has to use only one option as meta and the other as normal option)
EDIT: Also, a solution using Karabiner would be welcome too
it now support delay "Option::KEYTOKEY_DELAYED_ACTION"
https://pqrs.org/osx/karabiner/xml.html.en#syntax-KeyToKey-options
Starting form ant's solution and digging inside the Karabiner.app package to see how it works, I found a way to make it work using only Karabiner :
Simply edit your Karabiner private.xml (found in ~/Library/Application Support/Karabiner/private.xml )
to the following :
<?xml version="1.0"?>
<root>
<appdef>
<appname>TERMINAL</appname>
<equal>com.apple.Terminal</equal>
</appdef>
<item>
<name>Option-Left to Meta in Terminal</name>
<only>TERMINAL</only>
<identifier>private.optionltometa</identifier>
<autogen>__KeyToKey__ KeyCode::OPTION_L, KeyCode::VK_MODIFIER_EXTRA1</autogen>
<include path="/Applications/Karabiner.app/Contents/Resources/include/checkbox/apps/terminal/meta_modifier_key.xml">
<replacementdef>
<replacementname>BEFORE</replacementname>
<replacementvalue>KeyCode::ESCAPE</replacementvalue>
</replacementdef>
<replacementdef>
<replacementname>AFTER</replacementname>
<replacementvalue></replacementvalue>
</replacementdef>
</include>
</item>
</root>
Then launch Karabiner and press the Reload XML button in the Change Key tab (I'm using version 10.22.0, maybe the tab names have changed in newer versions)
The advantage of this method is that it does not disable your left option key when you are not using Terminal, as the solution using Seil does.
You should be able to use a combination of Seil and Karabiner to get this done. First, install Seil and remap the Option_L key to keycode 110, which is the PC Application Key. Then in Karabiner, expand For Applications tree and then Enable at only Terminal and finally Meta Modifier Key. Select the PC Application Key to Meta Modifier Key in Terminal option.
Related
I tried to use Alt as meta key for the FSF Emacs 23 Windows version and for EmacsW32 but especially M-x (Alt-x) does not work.
Somehow I cannot use Alt as Meta key for Alt-x (M-x). I searched really hard and all I got is how to switch the meta key to Alt in w32-meta-style. Currently this variable has the value 'use Alt as Meta key'. I also tried all other values with no success. Furthermore I installed the unpatched version of emacs from http://ourcomments.org/Emacs/EmacsW32.html and the original binaries from gnu.org. All versions have the same problem.
Alt works as Meta, except for Alt-x (Meta-x).
My setup is as follows:
Windows 7 x64 Professional
German keyboard
This question is Windows specific as I have a working Ubuntu version of Emacs 23.
EDIT: It was Growl for Windows. It loads on start up and caputes all Alt-x inputs. So my solution was to just disable Growl as I do not need it anymore. Might be another App for you.
It should work out of the box. Does Alt+x work as M-x if you start Emacs with the -Q flag? That inhibits loading of your customizations, in case one of them is breaking M-x on Windows.
Also, Emacs only treats the left Alt key as Meta by default, the right Alt (AltGr), is used for entering special characters .
I don't know about w32-meta-style but did you set w32-alt-is-meta? See http://www.gnu.org/software/libtool/manual/emacs/Windows-Keyboard.html
The Growl hotkeys can be changed:
https://groups.google.com/forum/#!topic/growl-for-windows/luSpf9lQQRM
To disable the hotkeys, just remove the content of the 'value' tags.
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.
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.
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,
How do I make Caps Lock work like Esc in Mac OS X?
Edit: As described in this answer, newer versions of MacOS now have native support for rebinding Caps Lock to Escape. Thus it is no longer necessary to install third-party software to achieve this.
Here's my attempt at a comprehensive, visual walk-through answer (with links) of how to achieve this using Seil (formerly known as PCKeyboardHack).
First, go into the System Preferences, choose Keyboard, then the Keyboard Tab (first tab), and click Modifier Keys:
In the popup dialog set Caps Lock Key to No Action:
2) Now, click here to download Seil and install it:
3) After the installation you will have a new Application installed ( Mountain Lion and newer ) and if you are on an older OS you may have to check for a new System Preferences pane:
4) Check the box that says "Change Caps Lock" and enter "53" as the code for the escape key:
And you're done! If it doesn't work immediately, you may need to restart your machine.
Impressed? Want More Control?
You may also want to check out KeyRemap4MacBook which is actually the flagship keyboard remapping tool from pqrs.org - it's also free.
If you like these tools you can make a donation. I have no affiliation with them but I've been using these tools for a long time and have to say the guys over there have been doing an excellent job maintaining these, adding features and fixing bugs.
Here's a screenshot to show a few of the (hundreds of) pre-selectable options:
PQRS also has a great utility called NoEjectDelay that you can use in combination with KeyRemap4MacBook for reprogramming the Eject key. After a little tweaking I have mine set to toggle the AirPort Wifi.
These utilities offer unlimited flexibility when remapping the Mac keyboard. Have fun!
Since macOS 10.12.1 it is possible to remap Caps Lock to Esc natively (Apple > System Settings… > Keyboard > Keyboard Shortcuts > Modifier Keys in macOS 13, or, before, System Preferences -> Keyboard -> Modifier Keys).
I wasn't happy with any of the answers here, and went looking for a command-line solution.
In macOS Sierra 10.12, Apple introduced a new way for users to remap keys.
No need to fiddle around with system GUIs
No special privileges are required
Completely customisable
No need to install any 3rd-party crap like PCKeyboardHack / Seil / Karabiner / KeyRemap4MacBook / DoubleCommand / NoEjectDelay
If that sounds good to you, take a look at hidutil.
For example, to remap caps-lock to escape, refer to the key table and find that caps-lock has usage code 0x39 and escape has usage code 0x29. Put these codes or'd with the hex value 0x700000000 in the source and dest like this:
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}'
You may add other mappings in the same command. Personally, I like to remap caps-lock to backspace, and remap backspace to delete:
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x70000002A}, {"HIDKeyboardModifierMappingSrc":0x70000002A,"HIDKeyboardModifierMappingDst":0x70000004C}]}'
To see the current mapping:
hidutil property --get "UserKeyMapping"
Your changes will be lost at system reboot. If you want them to persist, configure them in a launch agent. Here's mine:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!-- Place in ~/Library/LaunchAgents/ -->
<!-- launchctl load com.ldaws.CapslockBackspace.plist -->
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.ldaws.CapslockEsc</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/hidutil</string>
<string>property</string>
<string>--set</string>
<string>{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x70000002A},{"HIDKeyboardModifierMappingSrc":0x70000002A,"HIDKeyboardModifierMappingDst":0x70000004C}]}</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
I've placed this content into a file located at ~/Library/LaunchAgents/com.ldaws.CapslockBackspace.plist and then executed:
launchctl load com.ldaws.CapslockBackspace.plist
The only thing I know how to do is to map Caps Lock to Control, or Option, or Command. This can be done via the Keyboard & Mouse pane of System Preferences. Click on "Modifier Keys" on the bottom left and you'll be able to remap Caps Lock, Control, Option, and Command, to any of those.
#Craig:
This suggests that Caps Lock can be used as a normal -- that is, non-toggle -- key. On my MacBook, since I have re-mapped Caps Lock to Control, the Caps Lock light never lights up. It simply acts like the Control key.
It is now much easier to map the Caps Lock key to Esc with macOS Sierra.
Open System Preferences → Keyboard.
Click the Modifier Keys button in the bottom right-hand corner.
Click the drop down box next to the hardware key that you’d like to remap, and select Escape.
Click OK and close System Preferences.
https://9to5mac.com/2016/10/25/remap-escape-key-action-macbook-pro-macos-sierra-10-12-1-modifier-keys/
It's possible.
Solution 1
From an arcticle on TrueAffection.net.
Download PCKeyboardHack and install it.
Go to PCKeyboardHack in System Preferences.
Enable ‘Change Caps Lock’ and set the keycode to 53.
Solution 2
This solution doesn't involve patching the keyboard driver, but gives you a Vim specific solution.
OS X supports mapping the Caps Lock key to a whole bunch of keys, but you have to do it 'by hand', editting .plist files. The process is described in this article. As addendum to that hint I suggest you first set Caps-Lock to None in the System Preferences, then you only need to change one value in the .plist file. Also, you can of course use the Property List Editor instead of going through the XML conversion steps.
The trick is to map the Caps Lock key to the Help key (code 6), which isn't on most keyboards. But if it is, it will be treated as the insert key, which you probably don't use anyway, since you ask about remapping your Caps Lock to prevent stretching your hands ;)
You can then map the Help and the Insert key to Esc in vim.
map <Help> <Esc>
map! <Help> <Esc>
map <Insert> <Esc>
map! <Insert> <Esc>
This will work for gvim (Vim.app). I didn't get it to work with vim in the Terminal and I haven't tested it with MacVim.
So, it's rather a complicated, half-baked solution or installing a third-party piece of hackery. Your pick ;)
Edit: Just noticed solution 3, if you're using MacVim you can use Ctrl, Option and Command as Esc. With the System Preferences it's trivial to map Caps Lock to one of those keys.
Seil isn't yet available on macOS Sierra (10.12 beta). As such, I've been using Keyboard Maestro with these settings:
Credit to this github comment: https://github.com/tekezo/Seil/issues/68#issuecomment-230131664
Having tried several of these solutions, I have some notes:
DoubleCommand will not allow you to swap esc and caps-lock.
PCKeyboardHack will allow you to map capslock to escape, but does not have the capability to map escape to capslock. Recent versions will allow you to perform a complete swap by editing both keys.
This may or may not be sufficient for your needs (I know it is for mine).
In case you don't want to install a third-party app and you really only care about vim inside iTerm, the following works:
Remap CapsLock to Help as described here.
Short version: use plutil or similar to edit ~/Library/Preferences/ByHost/.GlobalPreferences*.plist, it should look similar to this:
<key>HIDKeyboardModifierMappingDst</key>
<integer>6</integer>
<key>HIDKeyboardModifierMappingSrc</key>
<integer>0</integer>
Restart! A simple log-out and log-in did not work for me.
In iTerm, add a new key mapping for Help: send hex code 0x1b, which corresponds to Escape.
I know this is not exactly what was asked for, but I assume the intent of many people looking for a solution like this is actually this more specialized variant.
In order to actually swap the escape key with the caps lock key (not just map one to the other) using both PCKeyboardHack and KeyRemap4MacBook, you have to follow the instructions in this thread, mapping the caps lock key to a keycode not used by the keyboard but accounted for by KeyRemap4MacBook (eg. 110). Then, in PCKeyboardHack, select the appropriate option that maps that keycode to escape (in the case of 110, it's "Application Key to Escape"). Here's what your KeyRemap4MacBook preferences should look like (provided you've selected the "show enabled only" checkbox).
I originally attempted to post this information as an edit to cwd's excellent answer, but it was rejected. I encourage anyone who wants to go the route that I describe to first read his/her response.
Open up Keyboard preferences and click modifier keys... you can change the caps lock key to control, option, escape, or command.
Seil doesn't work on macOS Sierra yet, so I'm using Karabiner Elements, download from https://pqrs.org/latest/karabiner-elements-latest.dmg.
Either use the GUI or put the following into ~/.karabiner.d/configuration/karabiner.json:
{
"profiles" : [
{
"name" : "Default profile",
"selected" : true,
"simple_modifications" : {
"caps_lock" : "escape"
}
}
]
}
You can also use DoubleCommand to remap this, and other keys.
IIRC, it will map Caps Lock to Esc.
Karabiner-Elements
A powerful and stable keyboard customizer for macOS. (freeware)
https://pqrs.org/osx/karabiner/index.html
Worked for me for Mojave to change caps-lock to backspace
With the latest Ventura update, System Settings changed.
You will find it on
System Settings > Keyboard > Keyboard Shortcuts > Modifier Keys