How to disable generating special characters when pressing the `alt+a`/`option+a` keybinding in Mac OS (`⌥+a` )? [closed] - macos

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
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?
Thank you

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:
MacOS <= 10.10
MacOS >= 10.11
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 (or Keyboard -> 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.

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

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.

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

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.

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.

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.)

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.

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/

Related

Customize word boundaries of Option-Delete (and other word related shortcuts) in macOS?

Is it possible to change the behavior of ⌥⌫ (option+delete) to include certain characters, like a period, as a word boundary?
For example, in some.variable, I would like ⌥⌫ to delete up to the period but it currently deletes the entire string. The screencast below shows the behavior using ⌥⇧←.
Screencast GIF
I've looked high and low for a solution to this issue since the Cocoa-era, as far as I can tell there isn't a way to customize the "Option-Delete" word-delimiter (word-boundary) list. In addition to my own experiments, I'm basing this conclusion largely on the enormous number of MacOS keybinding modifications that can be found at the following 3 URLs (from oldest to most recently updated):
Customizing the Cocoa Text System (circa 2006)
DefaultKeybinding.dict (circa 2016, some info previously at the URL "lri.me")
Keybindings -- BrettTerpstra.com (last updated 2018)
AFAIK, word-boundaries on MacOS default to whitespace and can't be changed. [This conclusion is invalid if there have been recent radical changes to MacOS text-input system].
It's no secret that many of the MacOS keyboard shortcuts are based upon eMacs-style 'keyboard-chording', as opposed to Vim-style 'modal-editing'. Indeed much of the Keybinding work cited above deals with remapping these chords. Vim of course is well-known for having a customizable delimiter list, it's the basis for differential word-movements between (for example) w, W and b and B (see vimhelp.org).
There have been a few extensions that have tried to bring 'Vim-style' editing to the MacOS, one of which is Karabiner. Karabiner (now re-written/updated to Karabiner-Elements) used to have a mode called "Ubiquitous_Vim". However without an OS-level 'hook' personal tests indicate that (for example) moving backwards via b and B works identically (i.e. there's no difference between a Vim word and a Vim WORD, see this StackOverflow post).
While I'm unable to find a way to modify the MacOS default 'word-boundary' list, if Vim-style editing does appeal to you, then you might try installing a project such as Vim-Anywhere, which enables you to 1. use a MacOS keyboard shortcut to open a Vim window whenever you need to enter text, and 2. will automatically copy your text to the MacOS System Clipboard when you close the Vim window. See this OSTechNix article: "How To Use Vim Editor To Input Text Anywhere" for more information.

Standard (no third-party) way to get numeric keypad working as arrow keys on macOS (Xcode? hidutil?)

I always use numeric keypad as arrows, as I find it more convenient than using an separate arrow pad. Until recently I used a tool Karabiner Elements, but it stopped functionning at Big Sur.
Yes, The Karabiner developer is working on that issue, but it will be better to solve it without relying on a third-party tool.
It will be enough for me to either remap Xcode, or (which is preferred) to change key bindings in the system, using a tool like hidutil.
Xcode's Preferences - Key Binding has a section Text - Section. When I try to modify the binding for say Move Down by pressing Down arrow on numeric keypad it comes up as '2'. Now whereever I press '2', on keyboard or numeric keypad, it always works as Move Down which is certainly not what I am after.
About hidutil. I couldn't find a good manual or any example of keyboard mapping.
Any help?
Had another look at this article. Here is the answer:
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x70000005A,"HIDKeyboardModifierMappingDst":0x700000051},
{"HIDKeyboardModifierMappingSrc":0x700000060,"HIDKeyboardModifierMappingDst":0x700000052},
{"HIDKeyboardModifierMappingSrc":0x70000005C,"HIDKeyboardModifierMappingDst":0x700000050},
{"HIDKeyboardModifierMappingSrc":0x70000005E,"HIDKeyboardModifierMappingDst":0x70000004F},
{"HIDKeyboardModifierMappingSrc":0x70000005F,"HIDKeyboardModifierMappingDst":0x70000004A},
{"HIDKeyboardModifierMappingSrc":0x700000061,"HIDKeyboardModifierMappingDst":0x70000004B},
{"HIDKeyboardModifierMappingSrc":0x700000059,"HIDKeyboardModifierMappingDst":0x70000004D},
{"HIDKeyboardModifierMappingSrc":0x70000005B,"HIDKeyboardModifierMappingDst":0x70000004E},
{"HIDKeyboardModifierMappingSrc":0x700000062,"HIDKeyboardModifierMappingDst":0x700000049},
{"HIDKeyboardModifierMappingSrc":0x700000063,"HIDKeyboardModifierMappingDst":0x70000004C}]}'
Still can't fugure out, how to do (if possible) complex mapping with modifier keys (eg Ctrl+PgUp to Home), but that's another topic.

Is there a way to make alt-f and alt-b jump word forward and backward instead of printing ƒ and ∫ on Mac?

I understand that Mac has some Emacs keybindings enabled by default (e.g. Ctrl+A move to beginning of line etc.). If I open TextEdit for example I can navigate like in Emacs.
But when I try Alt+F or Alt+b for move to next word or last word it does not work. It prints out ƒ and ∫ instead.
Is there a way to jump words instead?
I think that I did not tinker with the keybindings and I use the US layout on a german keyboard.
If you want to re-enable them for the terminal
Terminal -> Preferences -> Keyboard
Check 'Use Option as Meta key'
my iTerm2 version is 3.1.6, profile -> keys -> set Esc+
Maybe one of these helps? (I don't use OSX myself, so I can't test anything).
http://blog.sensible.io/2012/10/19/mac-os-x-emacs-style-keybindings-everywhere.html
http://aufflick.com/blog/2006/01/10/emacs-keybindings-everywhere
Summary from first URL:
Create file ~/Library/Keybindings/DefaultKeyBinding.dict with the following content and restart all apps.
{
"~d" = "deleteWordForward:";
"^w" = "deleteWordBackward:";
"~f" = "moveWordForward:";
"~b" = "moveWordBackward:";
}
I'm a little confused if you're talking about the keys (within different apps on OS X) or specifically Emacs. On OS X the standard keys you would use to jump between words is:
option/alt + Left Arrow or Right Arrow
If it's specific to Emacs for OS X:
For Terminal.app, starting from Snow Leopard: Go to Preferences > Settings > Keyboard > Use option as meta key.
For iTerm: Go to Manage Profiles > Keyboard profiles > (your profile) > Option Key as…
If you want to use Option key for both international characters and
Meta key in Emacs, see info below for iTerm 0.10.x patch and/or binary.
Alt-b and Alt-f for navigating by word also works for your shell now.
UPDATE: The link the original website providing the patch is no longer online, however I was able to retrieve the cached information from the archive.org:
OSX + terminal + Meta key + national characters
Quite a mix, right? If you’re user of one of those keyboard layouts that have hidden some non-ISO1 characters under Option-key shortcuts and you use command line – read on, I might have a treat for you.
As it stands today, if you’re OSX user, and would like to use your Option (Alt) keys for both national characters and Meta-* shortcuts, you’re in for an unpleasant surprise – you can’t. It’s one or the other: both iTerm and Terminal.app allow you to flip between Option keys role, but neither of them allows you to use Option for both. Under Linux, it’s customary to use left Alt for Meta-* and right Alt for any national characters you might require. Same goes for Windows. Of course you can just train yourself in using ESC key in a prefix manner, but that’s avoiding the real problem.
Getting annoyed by this state of things, and faced with some Emacs usage, I decided to take advantage of the fact that iTerm is opensource software, and see if I can make a tiny change, to cater for my needs. Surely enough, after ~25 minutes I got a trivial patch: just changed the mask that iTerm uses for detecting that Option key is pressed down. It took few hours and 5 chapters of Cocoa book, to turn that into fully-fledged option in Keyboard Profiles section of iTerm. This was my first foray into lands of Objective C; while I came back victorious, I don’t see myself writing anything bigger in Objective C in nearest future.
Here’s the meat: ( https://sourceforge.net/p/iterm/patches/44/ )
“right Option is Normal” patch;
full patch allows you to pick which keys should be treated as Meta (both, only left, only right);
The patches were made against 0.10.x branch, at revision
1871.
Once you have the binary, launch it and go to Bookmarks > Manage profiles > Keyboard profiles. If you select a keyboard profile, you should see a new dropdown at the bottom of the keybindings list.
The options should be pretty much self-explanatory. The configuration shown above is the one I’m using — this way I get all Meta-* shortcuts with my left Option key, and all Polish characters with right Option key. Which is the way it Should Be™ :)
I haven’t heard from iTerm authors yet, so I have no idea whether this patch is going to merged upstream or not. I’ve been using my patched version for almost week and a half now, and nothing major exploded. Yes, iTerm is slower to redraw the screen on larger terminals (say, 130×80), but there are certain features (like 256 colors support) that make up for that.
more info: http://www.emacswiki.org/emacs/EmacsForMacOS
On iTerm2 3.0.15, go to:
Preferences -> Default -> Keys tab ->"Left option() key acts as:"
and change the value to:
+Esc
Solved this at the OS level as follows,
⟶ System preferences
⟶ Keyboard
⟶ Input Sources Tab
⟶ + at bottom left
⟶ Others in the left panel
⟶ add and select Unicode Hex Input from right panel
 ✓  Mac no longer prints anything on alt+letter|number
 ✓  enter unicode characters via alt+[code]
 ✅ the OS does not grab alt key shortcuts!
You should use KeyRemap4MacBook. In the Emacs Mode section, you will find numerous options to use the Option key as Meta including Option+BF to Option+Left/Right.
However, if you're a hardcore Dvorak user like myself who wants to use key bindings such as M-b and M-f using the original Dvorak layout, there's a problem. You can only "move backward/forward one word" in QWERTY layout. I use version 8.4.0 so I don't know about the latest version for Mavericks.
I use BetterTouchTool. Works like this:
Basically remaps Option-F and Option-B to Option-Right and Option Left, and I turned this on for any apps that I want the shortcut in, e.g., Firefox, Obsidian, Slack. Works great!
For Hyper you can fix the option key by setting the following configuration to your ~/.hyper.js file:
module.exports = {
config: {
modifierKeys: { altIsMeta: true }
}
}
source

Mac OS X Terminal [Use option as meta key] overrides backslash in spanish keyboard [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I check "Use option as meta key" checkbox in Mac OS X Terminal, because I like to use emacs way of moving between words: M-f & M-b.
But if I do that, I can't get the backslash (Option + º; i.e.: Option + key-at-the-left-of-1-in-spanish-keyboard).
If I uncheck it, then I can input the backslash, but I don't have M-f & M-b.
Is there a way to get both?
The escape key works as a meta key by default; no need to use option as the meta key (other than its more convenient location).
Not a great solution, but XTerm (running in X11 on OS X) can use CMD as the Meta key.
You might also have some good results from KeyRemap4MacBook.
Just as a side benefit, XTerm should also give you proper terminal mouse interaction, e.g. in Emacs or ncurses based apps.
You will most likely run into a lot more problems with that setup, because Mac OS uses "Alt" as a modifier in a lot of shortcuts. But anyway, including the following line in your ~/.bash_profile will send a backslash if you enter the unicode character "∫" (which is E288AB):
bind '"\033\xE2\x88\xAB"':'"\\"'
You could customize the keyboard map to use a different key for entering backslash. Look in
Preferences > Settings > [profile] > Keyboard
For example, you could map Control-F1 to backslash.
Note that the default keyboard map maps Option-Left/Right Arrow to M-b/f, so you could use those instead of using Option for Meta (you’d have to get used to using the arrow keys instead of b and f, but I’ve never been able to get used to using b and f and prefer the arrow keys).
I had the same issue. This is how I solved it.
I replaced the built in terminal with iTerm2, which also gave me a few other nice features. To get a sane Meta-key i did the following:
For the profile I wanted to use I checked "Alt sends +Esc", which gave me back a sane Meta-key that works in Emacs, Bash and others. However, I did lose the backslash key. So, to get it back and added a binding in the profile that does "Send text: \" and then I bound it to my backspace key combo (Shift-Alt-7, I'm Norwegian).
Now I have M-f, M-b in Emacs, M-. in Bash and I'm able to send backslashes. I also have a "Visor shell session" that I can have slide down by pressing another key combination.
This is years late, but for people coming across this page whilst searching for a solution, as I did, I have decided to build one myself.
It is a simple status bar app that runs in the background and rewrites all left-Alt + $KEY key events to two key events in rapid succession, Esc, then $KEY; however, it only does this if Terminal.app is the focused application.
You can find it here at https://github.com/habibalamin/Metalt.

Meta and # in a UK mac terminal

In the mac terminal application there is a setting (preferences -> keyboard) that lets you set "use option as meta key". This is useful as a lot of unix boxes use bash as default shell and that has emacs keybindings M-f and M-b that let you skip words.
Problem is that on a Mac with a UK keyboard the # symbol is tricky to get to - normally it can be typed with alt-3, but not if you are in a terminal and alt=meta.
Anyone have a nice way round this?
I am using zsh and the following saved my day:
bindkey -s '^[3' \#
Set your keyboard language ( System Preferences->International->InputMenu ) to Australian
It is the same as UK except shift-3 gives #. You do lose the pound sign but if I do currency I use the ISO three character code GBP
The Australian layout is identical as mentioned except # is mapped to Shift 3 and £ is mapped to Alt 3.
Swap to Aus and the swap your ALT behaviour. This has annoyed me for while especially as it is in a non UK position to start with.
Earlier today I stumbled on a great solution to this on Graeme Sutherland's blog so thought I'd summarise it here in case it disappears.
If you want to stick with the built-in Terminal and don't want to lose the £ sign, you can use Ukelele roll your own keyboard layout to switch the section (§) key for hash instead. Quite a handy location for typing '#!' too :)
The keymap file Graeme created is here, but if you want to make your own you can simply take the British one as a base it's pretty straightforward to create the new keymap file.
Copy your new keymap file to ~/Library/Keyboard Layouts
Go to System Preferences - Language & Text - Input Sources
Scroll down to 'British with # for §' (or whatever you put as its name in Ukelele) and check the box
Check 'Show Input menu in menu bar'
Click on the flag in your menu bar at the top of the screen and choose your new input source
This input source can then be used in all apps, or just the ones you want it for.
I appreciate this and the linked question are quite old but thought this might help someone else.
ESC is another meta shortcut :). You don't have to keep pressing it though.
So in your situation, you might just need to press ESC once, and then press alt-3.
See image to get the details as to how to setup a shortcut in your terminal and fly free
I'm using iTerm2 and I was having this problem. With iTerm2 you can use the left alt key as a meta key, and the right as a normal key. So ralt-3 does the # key.
Based on ericteubert answer for zsh for bash you bind the key, I've added this to my .bash_profile:
bind '"\e3":"#"'
For vim you can add the following to your .vimrc
inoremap <ESC>3 #

Resources