188

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 combination alt+a will generate å.
the combination alt+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 the alt 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?

7
  • 41
    I'm using IntelliJ and I would like to simulate emacs keyboard shortcuts and I mapped meta to option key. But when I press, say, option-b, I did get the expected behavior as it is interpreted as a special character.
    – ximyu
    Commented Aug 9, 2012 at 7:03
  • 3
    If I use option key as a modifier, I can define even more shortcuts in my IDE, which sugnificantly boosts my productivity.
    – Dan
    Commented Apr 16, 2013 at 9:15
  • 50
    It's simply ridiculous how hard are such simple actions on Macs. Placed a wrong app in launcher - good luck removing it with SQL statements; want to disable some stupid shortcut - start downloading and testing zillion solutions which are not consistent across OS versions. God, why did I buy this awful computer?
    – Vasiliy
    Commented May 7, 2016 at 6:11
  • 3
    This works for me : superuser.com/a/942256/535138
    – 김민준
    Commented Feb 10, 2017 at 6:44
  • 5
    For people having problem on terminal, follow this instruction -> superuser.com/questions/496090/…
    – A-letubby
    Commented May 17, 2018 at 4:22

9 Answers 9

102

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!

  1. Download the key mapping file My Layout.keylayout.
  2. Move it to ~/Library/Keyboard\ Layouts/
  3. Open System Preferences -> Language Input Methods (or Keyboard -> Input Sources)
  4. Go to Input Sources -> (hit +) -> Select Others
  5. 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.

26
  • 1
    @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.. Commented Feb 7, 2014 at 4:40
  • 5
    The dropbox link appears broken now. Commented Apr 21, 2014 at 22:21
  • 3
    Could 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.... Commented Aug 10, 2014 at 16:44
  • 14
    This is not work in 10.11 anymore. I generate a layout file in gist.github.com/haosdent/573ea124e5ea666fc576 which works in 10.11
    – haosdent
    Commented Mar 7, 2016 at 8:12
  • 2
    Didn't work for me. Instead of option+r typing ®, it now types r in IntelliJ :(
    – Navin
    Commented Apr 5, 2018 at 23:39
54

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)

  1. Download Ukelele
  2. You can run it directly from the .dmg file
  3. File -> New Based On Current Input Source (I had US selected)
  4. Click Modifiers button
  5. 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
  6. Go to Keyboard menu -> Set Keyboard Name
  7. Change the name somehow to make it easier to identify
  8. Go to File -> Save as
  9. Save to ~/Library/Keyboard\ Layouts/ with suffix .keylayout
  10. Log out from your Mac OS account
  11. Log back in
  12. Go to System Preferences -> Keyboard -> Input Sources
  13. Hit the + button -> Others -> Your new layout should be available
  14. Add the new layout
  15. Possibly leave original keyboard layout too and configure some nice way to switch
12
  • 3
    This is the only solution that worked for me and allowed me to rebind the key combos to Emacs-like commands.
    – event_jr
    Commented Aug 7, 2014 at 13:34
  • @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?
    – Sahas
    Commented Jan 15, 2015 at 11:33
  • 1
    As 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
    – Innokenty
    Commented May 6, 2015 at 16:30
  • 2
    @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. Commented May 7, 2015 at 5:11
  • 1
    In 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. Commented Aug 24, 2015 at 17:17
41

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.

3
  • 21
    This 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. Commented Jan 25, 2014 at 21:51
  • @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. Commented Jun 7, 2014 at 17:57
  • I 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. Commented Jun 7, 2014 at 17:59
16

Use Ctrl-Alt-<MNEMONIC>. IMHO much easier than having to install and configure a separate app.

4
  • 4
    Good to know. However this is not completely satisfactory if also the Ctrl-Alt- key combinations have functions. Commented Jan 15, 2015 at 19:33
  • 5
    For 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.
    – ARKBAN
    Commented Aug 10, 2015 at 14:53
  • 1
    this answer is what you get if you ask JetBrains
    – Kirby
    Commented Nov 30, 2016 at 18:49
  • Welp. At least this has resolved my issue of trying to commit/push things using the shortcuts. Thanks!
    – gowl
    Commented May 16 at 12:34
12

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.

5
  • I tried this but still got an annoying character with Option+N for example in Intellij IDEA.
    – Amir Eldor
    Commented Jun 26, 2018 at 8:28
  • 5
    I used the keyboard layout "Unicode Hex Input" (under "Others"). It looks Identical to the U.S. layout but with the alt-combos blanked.
    – Coops
    Commented Dec 1, 2022 at 7:26
  • @Coops thanks, that's the only keyboard that worked for me Commented Aug 5, 2023 at 22:15
  • this is what worked for me. I had ABC-india selected earlier, changing it to "British" keyboard fixed the options key. version - Ventura 13.5 Commented Sep 26, 2023 at 6:06
  • thank you Coorps, this is the easiest solution and so far no downsides.
    – humazed
    Commented Jul 28 at 19:04
10

I have a solution! Place a file at: ~/Library/KeyBindings/DefaultKeyBinding.dict as:

/* ~/Library/KeyBindings/DefaultKeyBinding.dict */
 {
    /* Additional Emacs bindings */
    "~f" = "moveWordForward:";
    "~b" = "moveWordBackward:";
    "~<" = "moveToBeginningOfDocument:";
    "~>" = "moveToEndOfDocument:";
    "~v" = "pageUp:";
    "~d" = "deleteWordForward:";
    "~^h" = "deleteWordBackward:";
    "~\010" = "deleteWordBackward:";  /* Option-backspace */
    "~\177" = "deleteWordBackward:";  /* Option-delete */

    /* Escape should really be complete: */
    "\033" = "complete:";  /* Escape */        
}

It will hide the original textual input. But you can still get that by using Ctrl-Q before the combination. So Ctrl-Q Alt-f gives me ƒ for example. In fact, I'm writing this answer with the option keybindings enabled. You can also add other keys you like! Official reference: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html

Here is a good list of things you can bind to: https://www.hcs.harvard.edu/~jrus/site/selectors.html

Oh, by the way, if you bind a key to an undefined action, your application will have a memory leak and your system will run out of memory in a few seconds. Tested on el capitan, in the hard way.

3

Use ABC as input method instead of ABC-Extended, then option + [char] would be able to use the application shortcut instead of showing special character.

2
  • 1
    This answer helped me, Instead of ABC-Locale or ABC-Extended, I used ABC Commented Mar 28, 2020 at 19:46
  • 1
    This 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.
    – SOFe
    Commented Apr 27, 2022 at 6:01
2

Using the Apple JRE, the Option key combinations will work as shortcuts instead of inserting special characters.

Download link: https://support.apple.com/kb/DL1572?locale=en_US

It's an old outdated JRE (based on Java 6) but as of October 2015 it's still what seems to work best w/ my JetBrains RubyMine installation. (Anything else, the keys go back to inserting special characters.)

0
0

I have found a decent workaround. I use the software Karabiner to change my right enter key to control when held down.

So what iv done is remapped the option key to option+cmd+control, as I'm not aware of any commands that use all three modifiers. Now I can map the right shortcuts without any characters. But you could also map to additional keys if required

Add this to your private.xml: (in between root)

<item>
<name>Change option Key to cmd + control + option</name>
<identifier>private.optiontoelse</identifier>
<autogen>__KeyToKey__ 
    KeyCode::OPTION_L, 
    KeyCode::OPTION_L, ModifierFlag::CONTROL_L | ModifierFlag::COMMAND_L</autogen>
<autogen>__KeyToKey__ 
    KeyCode::OPTION_R, 
    KeyCode::OPTION_R, ModifierFlag::CONTROL_R | ModifierFlag::COMMAND_R</autogen>
</item>

Then reload the xml and enable the option at the top of the 'Change Key' tab

https://pqrs.org/osx/karabiner/

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.