How to disable generating special characters when pressing the `alt+a`/`option+a` keybinding in Mac OS (`⌥+a` )?
Solution 1
I was having the exact same problem, in the exact same IDE.
The solution to this is to download Ukulele from here:
http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=ukelele
In the application you can create a new keylayout using File -> New from current source. Pressing Option will show you in the place for Option-b a red colored key - meaning it's a dead key. Double clicking it will allow you to change it from a dead key to an output key. When prompted for the output you can put in the same thing (by pressing Option-b).
Thus it will output the same character but will not be considered a dead key, so Intellij can bind it as a shortcut.
To enable your new layout you must save it into your ~/Library/Keyboard Layouts (it helps if you give it a new name with Keyboard -> Set Keyboard Name), and then enable it from System Preferences -> Language & Text.
Solution 2
You can create a custom keyboard mapping with option-letters all set to BLANK using online tool from this webpage. You can create a custom mapping in several clicks out of almost any keyboard layout. Proved to work on MacOSX 10.7+ with IntelliJ Idea, Php/WebStorm, NetBeans, Eclipse.
Select "Set blank for option key" radio in the form, submit the form, and download a patched keyboard layout with "option" key feature disabled. I'm sharing the working file for standard US English keyboard layout:
After enabling this custom mapping, if you type a letter with "option" key pressed, nothing is printed to text output. But, the "option key press" is triggered by OS, and detected by your IDE. So you get exactly the same behaviour as you have for other command keys!
- Download the key mapping file
My Layout.keylayout
. - Move it to
~/Library/Keyboard\ Layouts/
- Open
System Preferences
->Language Input Methods
(orKeyboard
->Input Sources
) - Go to
Input Sources
->(hit +)
->Select Others
- You should find
My Layout
in the list and select it.
Step 4 can change slightly across MacOS versions. Please be patient to find keyboard layouts list in the settings.
Solution 3
Here are detailed steps to Sebastian Zaha's answer. (I ended up fumbling around a bit before I got this working).
(Alternatively here is a ready made file by me)
- Download Ukelele
- You can run it directly from the .dmg file
- File -> New Based On Current Input Source (I had US selected)
- Click Modifiers button
- Select each modifier from list that have Left Down or Right Down in the Option column. (There could be some like Either Down OR Up too, but AFAIK you can leave those.)
- Press the minus button for each like this
- Go to Keyboard menu -> Set Keyboard Name
- Change the name somehow to make it easier to identify
- Go to File -> Save as
- Save to ~/Library/Keyboard\ Layouts/ with suffix .keylayout
- Log out from your Mac OS account
- Log back in
- Go to System Preferences -> Keyboard -> Input Sources
- Hit the + button -> Others -> Your new layout should be available
- Add the new layout
- Possibly leave original keyboard layout too and configure some nice way to switch
Solution 4
Use Ctrl-Alt-<MNEMONIC>
. IMHO much easier than having to install and configure a separate app.
Solution 5
I had the same issue on a new Macbook with VSCode which had worked fine on my old Macbook. When I typed alt-shift-f for format I got unicode instead. I realised the difference was my old Macbook had a British keyboard setup instead of the default "ABC - Extended". Adding the British keyboard fixed the issue for me.
ximyu
Updated on August 07, 2021Comments
-
ximyu almost 3 years
There is a behavior in my mac that I'm trying to disable.
When I'm in any text editor and typing a key combination using the
alt
/option
+any letter, the output will be special characters.For example:
the combinationalt+a
will generateå
.
the combinationalt+x
will generate≈
.I want to cancel this behavior.
I'm a programmer and when I use my code editor I want to map some keybinding (keyboard shortcuts) to thealt
key (⌥+a
for example) but when I do that it doesn't execute because it generates the special characters.
I guess that the special character has a priority over my code editor shortcuts.Do you know how can I disable this default behavior?
Thank you
-
Dan almost 11 yearsI've made some testing and it works on 10.5 also. Usually using it for WebStorm and Idea. This increases the number of hotkeys much!
-
RussellStewart over 10 yearsworks great. Also, for those who would like to further map selected option+... keys to emacs commands, as they work in terminal or linux in general, you may want to check out Emacs Mode under keyremap4macbook.
-
WestCoastProjects over 10 yearsThis is a lot of work and only fixes one key combo in one app. I and at least some others would want to across the board disable opt as special characters input on mac.
-
WestCoastProjects over 10 yearsI went to the Input Sources Dialog but do not see any layouts list ? I put the file there /Users/steve/Library/Keyboard Layouts/BlankOptionKey.keylayout
-
Dan over 10 years@javadba, please try walking around the settings connected with keyboard input. You should find a vertical list with lots of languages supported. I don't have Mac nearby, so I can't give a good answer to your question.
-
WestCoastProjects over 10 years@Dan Yes there is a vertical list of languages - but how does that relate to "layouts list"? There is no "My Layout" there - just .. languages..
-
WestCoastProjects over 10 years@Dan I found out how to do this - the instructions were missing a step. Should be: keyboard | Input Sources | (hit +) | Select OTHERS (that's the missing step) | (then the "My Layout" shows up)
-
Dan over 10 years@javadba, I've corrected my answer. Thank you for your feedback!! Things could change with new OS versions.
-
Jaime Cham about 10 yearsThis seems to work, however it also seems to screw up shortcuts for other apps when the custom layout is selected. For example Ctrl-TAB doesn't work on Chrome anymore.
-
Dan about 10 years@JaimeCham strange, this is not connected with
Alt
button -
Andrew White about 10 yearsThe dropbox link appears broken now.
-
Frank Fang about 10 yearsAll keys do not work :(
-
Frank Fang about 10 yearsOh, I see what's wrong. You did not mention that maybe I should restart the application, like Chrome, to enable the new layout.
-
Peter Lamberg almost 10 years@javadba It wasn't that bad after I got it right. See my answer below for detailed steps which should be fast to click through.
-
Peter Lamberg almost 10 yearsI added an answer with detailed steps to what @SebastianZaha describes in this answer. I ended up fumbling about a bit to get it done, so hopefully it will save someone (and later me) some trouble.
-
Matt Smith almost 10 yearsConfirmed working on Yosemite DP5
-
event_jr almost 10 yearsI ran into problems with this solution: after disabling the special symbols, I couldn't bind some keys with
~/Library/KeyBindings/DefaultKeyBinding.dict
. stackoverflow.com/a/24100077/903943 is working perfectly. -
event_jr almost 10 yearsThis is the only solution that worked for me and allowed me to rebind the key combos to Emacs-like commands.
-
AgmLauncher almost 10 yearsCould not get this to work. I can add my new key layout to the list, but I cannot remove the default 'US' layout, thus it won't actually use my new key layout....
-
Kirby over 9 yearsThanks! Worked for me on Yosemite and Mountain Lion. On Yosemite (10.10), adding layouts is in Language & Region, Keyboard Preferences, Input Sources
-
Sahas over 9 years@event_jr, how did you rebind them for emacs behaviour? When you hold down option and click on b, it asks for output for that combination. How do we tell it that output is to go back a word?
-
event_jr over 9 years@Sahas This answer is about stopping key from interpreted as a special character. Once you do that, you have to edit DefaultKeyBinding.dict to enable Emacs commands for specific key combos.
-
Peter Lamberg over 9 yearsGood to know. However this is not completely satisfactory if also the Ctrl-Alt- key combinations have functions.
-
Drew over 9 yearsTurning on 'Leave Option blank' breaks Ctrl+/ in Emacs for me
-
Innokenty about 9 yearsAs for me I couldn't make this work on Yosemite: I followed all the instructions successfully, I see that in my browser for example I can not type alt+symbols, but in IDEA just nothing happens when I try to use a shortcut. I'm not sure how, I restarted it, but it seems not to pick up the info that now this key combination is blank and can be triggered as a shortcut.
-
Innokenty about 9 yearsAs I commented above this didn't help me to fix shortcuts in IDEA on Yosemite too. I'm afraid they changed something in newer versions and now it became not possible to fix this. I'm running IntelliJ IDEA 14.1.2 on OS X Yosemite 10.10.3
-
Peter Lamberg about 9 years@Innokenty Strange. I'm on OSX 10.10.3 and IDEA 14.1.2 and my emacs-like bindings work. I brought the IDEA config over from a windows machine and the .keylayout file was built using some older version of OSX. Could one of these be the reason? Here is my layout file.
-
Innokenty about 9 years@PeterLamberg Wow, this one works, thank you! Maybe I excluded the modifiers in Ukelele the wrong way. I left the 'Either Down's and 'Either Down OR Up's untouched.
-
Innokenty about 9 yearsAlso this link might be useful for those that want to remove the default 'U.S.' layout: apple.stackexchange.com/questions/44921/…
-
Peter Lamberg about 9 years@Innokentry Thanks for responding! I'm adding the file to main post too.
-
jmcmichael about 9 yearsI was also searching for a solution to the option keymapping problem in IntelliJ/10.10.3, and found this. And it worked - thank you @PeterLamberg! I was previously using cmd-key-happy, now I'm using Karabiner to swap option/command keys, and ctrl-space to select wasn't working until I added your keymap. One thing that was nice about cmd-key-happy is that you could specify 'passthrough' for sequence like cmd-tab for app switching. I could then hit option-tab to do this with cmd-key-happy but now it doesn't appear to do anything. Have you run into an issue like this? Thanks again.
-
bgs about 9 yearsThank you! I use Alt+Slash so many times...
-
ARKBAN almost 9 yearsFor IDE's CTRL+ALT is likely already used, so you have to reconfigure your IDE, which is equal pain to having to configure some other app.
-
duelin markers over 8 yearsIn OS X 10.10.5, I didn't see any "Left Down" or "Right Down" in the "Option" column: just "Either Down". I removed all those, and now have Emacs-style keybindings working in IntelliJ. I wish I understood what removing those rows meant, but since it's easy to switch input methods if I run into trouble, I'm going with it. Thanks.
-
haosdent about 8 yearsThis is not work in 10.11 anymore. I generate a layout file in gist.github.com/haosdent/573ea124e5ea666fc576 which works in 10.11
-
Kirby over 7 yearsthis answer is what you get if you ask JetBrains
-
Alexandre G almost 7 years@Innokenty If you export the layout as a bundle, then you can simply remove the other layout from preferences. If not working make sure you set script to Latin when saving bundle. Oh and this way you can keep the layout icon too.
-
Navin about 6 yearsDidn't work for me. Instead of option+r typing
®
, it now typesr
in IntelliJ :( -
Amir Eldor almost 6 yearsI tried this but still got an annoying character with Option+N for example in Intellij IDEA.
-
Bloke almost 6 yearssame thing here as for @Navin,
option
+letter now prints that letter to text output :( -
tiktak about 5 yearsGenerate from the website, because when I download the file from GitHub, then the characters appear in IntelliJ. Not so when I generate the file myself.
-
Bloke about 5 years@tiktak is right! I've just generated one myself using the
Yes, but leave the "option" keystrokes blank.
option, and it works perfectly :)) Thank you! (@Navin try like this) -
Code Name Jack about 4 yearsThis answer helped me, Instead of ABC-Locale or ABC-Extended, I used ABC
-
ijoseph over 3 yearsFor Karabiner-Elements, which uses
json
rather thanxml
and is necessary for newer MacOS versions, use this template: gist.github.com/ijoseph/dd136b7bdf622bbe54f7339db052df5e -
haosdent about 2 years@Navin Sorry that miss the message, I update my script at gist.github.com/haosdent/573ea124e5ea666fc576
-
HaterTot about 2 years2022, macOS Monterey: for some reason it wasn't enough to clear out the modifiers that had option. I had to explicitly add in a modifier set (with +, only select "option down") at index 0. Without doing so, for some reason the alt key would trigger some other map at another index. Doing so seems to explicitly say "when option is pressed, the letters on the keyboard are the same as if option wasn't pressed".
-
SOFe about 2 yearsThis does not disable special characters in general. I still have a chance of accidentally typing the multibyte dash
–
instead of the ASCII-
, which could lead to really confusing errors especially in languages with the->
operator.