Alt key when navigating in console - macos

In Ubuntu when using Alt modification key I can move between words using left/right arrows. But in OS X (iTerm2 actually) when pressing this key combination I get [D symbols. Do I need any additional libraries to make it work or how can I accomplish this for comfortable navigation?

Seems like this post cover how to deal with this issue. Will try it.
Also, similar Stack overflow question here

Related

Using Alt Key in FakeVim mode of Qt Creator?

It's really handy when you work with VIM text editor to use Alt key to execute normal mode commands in insert mode, for example when you are in insert mode you can press Alt + j to go one line down. But in FakeVim mode of Qt creator this couldn't be done. Any suggestion is welcome.
Pressing Esc each time you want to go to normal mode really sucks.
(not a fix to your problem, just discussing it in a properly formatted text)
I never hit <ESC> as well, and this is a deal breaker for me. Note that it's not a vim feature, though : this behavior occurs because using Alt with an other key in terminals generates an escape sequence. So there's nothing wrong with FakeVim regarding Alt implementation, the problem is related to the IDE being a QT window. You can't use Alt sequence in GTK's Gvim as well, for the same reason, last time I checked.
A possible easy fix on the QCreator part : provide an option to not pass Alt combinations, like the one existing for Ctrl. That is, if QT allows that. We could then at the very least define vim bindings using Alt key to simulate the terminal behavior.
In the list of others exotic combinations from terminals that quickly lead to form habits in vim, I also use C-j in place of <return>, and C-h instead of <backspace>. Those would really be nice to have too :)

How to disable generating special characters when pressing the `alt+a`/`option+a` keybinding in Mac OS (`⌥+a` )? [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
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/

OSX Option/Alt as Meta: Is there a way to port or use emulate-mac-keyboard-mode in standard Emacs 24?

Emacs 24.1 was just released, and I once again feel inclined to use the "real" Emacs (Cocoa GUI version, from http://emacsformacosx.com) instead of Aquamacs. The only thing keeping me in Aquamacs is this:
In AquamacsEmacs, Option (Alt) is mapped to Meta - however, because
Option is used to input a lot of non-ASCII characters such as ü or £
on a variety of keyboards, the special character input methods take
precedence by default. You can deselect “Option key produces only
special characters” in the Options menu to use Option as Meta, or you
set the variable mac-command-modifier to ‘meta - you will lose
functionality, of course. If you use a non-English keybboard layout,
the emulation modes might be just what you want. While they leave the
Option key mapped to Meta, they will allow you to input many common
characters ([,],{,},\, etc.) directly with the Option key, just as you
would otherwise. You can find them in the Options → Option Key menu -
or use, e.g., M-x emulate-mac-german-keyboard-mode.
This question speaks about the same issue, and one of the answers is "use Aquamacs".
So in Aquamacs, I can use Option key as Meta and everything is fine, I can type e.g. [ with option(alt)-8 and still use alt as meta when I add this into my .emacs:
(setq emulate-mac-finnish-keyboard-mode t)
But is there any way to use this feature in Emacs 24? Has anyone ever tried porting emulate-mac-‌​keyboard-mode.el to standard Emacs?
And no, cmd as meta is not an option for me.
Has anyone ever tried porting emulate-mac-‌​keyboard-mode.el to
standard Emacs?
I haven't tested it, but this answer to the question you linked claims to have done just that.
I am not using Emacs but when I tried to remap certain keys for VIM I had some wired trouble. I finally found out that these issues were caused by Terminal.app as it somehow did not pass through some key events. I then switched to iTerm2 which also had some additional features, e.g. X11 mouse events without need for plugins.
I use EmacsForMacosx. This claims to be pure gnu emacs.
The options you are asking for are easily available through customize-group ns
(from what I know the naming comes from NextStep which kinda was a precessor of OSX)
personally I set the fn key to meta as I hardly use it within emacs. And keep alt as used by mac. You can also set left and right alternate to different functions - like for german on windows keyboards.

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.

OS X Terminal: Meta key + alt functionality at the same time

Is there a way to use an alt / option key as a meta key but still be able to use it to make some characters which need it?
For example, in my local keyboard layout:
# is alt + 2
\ is alt + shift + 7
| is alt + 7
etc.
So, if I set alt as a meta key, I can't make those characters anymore. On the other hand, using "press esc, release esc, press a key" to make meta key sequences makes my hands hurt.
Any Emacs users with international keyboards who have solved this, please give any tips you might have! :)
Edit:
It appears that I can set alt as a meta key and then add these kind of settings in inputrc: "\e2": "#" This works in the bash shell but it still won't work with Emacs though, so no good.
I use a Swedish keyboard in Mac OS X and use the following setup for Emacs.app:
First I have KeyRemap4MacBook installed and I have it setup to change the left Option key to Command.
I then have the following in my .emacs:
(setq mac-option-modifier 'none)
(setq mac-command-modifier 'meta)
This makes Emacs treat command as Meta and ignore Option. Since the left Alt/Option key is remapped to command, this makes it work lite meta while the right Alt/Option key still works for entering special characters like # [] and {}.
App specific Mac shortcuts like Cmd+C and Cmd+V no longer work, but global shortcuts like Cmd+space for Spotlight and Cmd+Tab for app switching do.
Update:
If you use iTerm2 as a Terminal, that has support for mapping only the left Alt/Option key to meta, which means you can still use the right AltGr/Option key for entering special characters. This also means you can use meta as normal inside Emacs running in the iTerm2 terminal.
I have a Swedish keyboard on my Mac and I'm using Aquamacs. Adding the two lines (attribution goes to Joakim Hårsman)
(setq mac-option-modifier 'none)
(setq mac-command-modifier 'meta)
in .emacs (and restarting Aquamacs) did the trick for me.
with iTerm2 you can map the left option key to ESC/meta and leave the mapping of the right option key to "normal". This way you can use the right option key to type accents etc.
Think about using a full featured Emacs for Mac OS X. I use Carbon Emacs but I believe others (say Aqua Emacs or X11 Emacs) would do the trick.
If you insist on using Emacs in a terminal you can use the C-x 8 prefix as a compose key. Try C-x 8 C-h to get a list of possibilities.
See http://www.emacswiki.org/emacs/EmacsForMacOS
Two work-arounds I use:
I use xterm running under X11.app. X11.app uses the command key as meta.
When running emacs in Terminal.app, I just use the rfc1345 input-method, which allows me to enter all kinds of crazy non-ascii characters without needing an option key.
Check out cmd-key-happy. This little app has worked wonders for me. It allows you to use command as meta, with exceptions that you can configure.
Author's info follows:
This program allows you to swap the command and alt (or option) keys
in any application, but in particular Terminal.app.
http://github.com/aim-stuff/cmd-key-happy
This is an old post but adding an alternatives for Robots to find.
I borrowed a couple of files from Aquamacs(emulate-mac-keyboard-mode.el, aquamacs-tools.el) that fixes the problem (I have a Italian-Pro keyboard) :
(defun aq-binding (any)
nil)
(load "~/.emacs.d/emulate-mac-keyboard-mode.el") ;; 'noerror
this provides:
few minor modes (emulate-mac-italian-keyboard-mode,
emulate-mac-french-keyboard-mode,
mulate-mac-swiss-german-keyboard-mode, etc)
a menu to play with all the options provided by Aquamacs
Tested with Emacs-23.3-universal-10.6.6 and seems to work ok for me.
Thanks Aquamacs for this, what about pushing this upstream if not already done.
It's worth thinking about the assumption behind the question. I mean to say that the real problem is making the characters that currently seem to need the option key. This problem can be solved without achieving simultaneous 'meta key + alt functionality'.
Let me explain: I have a similar problem. On my UK keyboard, shift-3 is mapped to the pound sign, £, which means that I generally need to hit option-3 to get the very useful # - a real problem in Terminal, where I use option as meta. However, I find most of the above solutions to be a little over-the-top. I don't want to change to another version of Emacs (eg. Aquamacs), to switch to a different Terminal application (eg. iTerm or xterm), or to install a key-remapping application (eg. KeyRemap4MacBook) all for the sake of one symbol! Perhaps that would suit some people, but I thought it was worth pointing out that if the problem is just one character, it can be solved with a nine-character text file.
With regard to my personal version of this problem, I find the simplest solution is to create a file called .inputrc in my home directory, consisting of the following single line:
"§": "#"
This re-maps the (to me, quite useless) § that can be found to the left of the 1 on the current Mac keyboard to the (almost indispensable) #. That suits me even better than the default setup, because I can now get # with a single keypress. If there were any other characters I needed to remap, it would just be a matter of adding an extra line for each one.
Anyway, that deals with how to get the missing character in the shell, but if you also want it in Emacs (which you didn't say but is probably the case) then you can add something like this to your .emacs file (where 35 is the ASCII for the character I happen to want, ie. #):
(global-set-key (kbd "§") 'insert-hash)
(defun insert-hash ()
(interactive)
(insert 35))
It might not be such a neat solution if there were dozens of characters that I routinely wanted to access via the option key, but there aren't.
I hope this helps somebody. As a mere weekend hacker, I ordinarily wouldn't dare post an answer to a question on Stack Overflow...
Special keyboard layout with option deadkey
My solution to this problem is a special keyboard layout I have written, U.S. custom. It provides an option deadkey that produces option combos without having to use the physical ⌥ Option modifier key. For instance, the character ⟨ç⟩ is produced as follows on a normal U.S. keyboard layout:
Hit ⌥ Option+c.
The U.S. custom keyboard layout adds a second way of producing ⟨ç⟩:
Hit ⇧ Shift+§ (the option deadkey), then release it, then hit c.
This works even in Terminal.app when Use option as meta key has been checked.
Note that the U.S. custom keyboard layout does two additional things:
It converts plain § into a ⎄ Compose key (so you could also produce ⟨ç⟩ by hitting §, then ,, then c).
It replaces the CapsLock mapping by a (significantly extended) U.S. Extended keyboard layout.
Remap option deadkey to right option modifier key
If you have a physical ANSI keyboard, then you lack the § key. In that case, I recommend assigning the § key to some other key, for instance to the right ⌥ Option modifier key. Install KeyRemap4MacBook, open ~/Library/Application\ Support/KeyRemap4MacBook/private.xml and paste the following code:
<?xml version="1.0"?>
<root>
<item>
<name>Send ISO Section for right Option</name>
<identifier>private.send_iso_section_for_right_option</identifier>
<autogen>--KeyToKey-- KeyCode::OPTION_R, KeyCode::UK_SECTION</autogen>
</item>
<item>
<name>Send Shift+ISO Section for Shift+right Option (keep normal right Option without Shift)</name>
<identifier>private.send_shift_iso_section_for_shift_right_option</identifier>
<autogen>--KeyToKey-- KeyCode::OPTION_R, ModifierFlag::SHIFT_R, KeyCode::UK_SECTION, ModifierFlag::SHIFT_L</autogen>
<autogen>--KeyToKey-- KeyCode::OPTION_R, ModifierFlag::SHIFT_L, KeyCode::UK_SECTION, ModifierFlag::SHIFT_L</autogen>
</item>
</root>
Then, open the KeyRemap4MacBook preference pane, hit ReloadXML and then select “Send ISO Section for right option”. Now, your ⌥ Right Option key is remapped to §, so while the U.S. custom keyboard layout is active, hitting ⇧ Shift+⌥ Right Option will give you the option deadkey state (hitting ⌥ Right Option without additional modifiers will give you a deadkey state equivalent to the option modifier.
If want to keep ⌥ Right Option when ⇧ Shift is not pressed (instead of the ⎄ Compose key), then select “Send Shift+ISO Section for Shift+right Option (keep normal right Option without Shift)” in the KeyRemap4MacBook preference pane (instead of “Send ISO Section for right Option”). Like that, only ⇧ Shift+⌥ Right Option will produce the option deadkey, while plain ⌥ Right Option will continue to work as an option modifier. You can even continue using ⌥ Right Option+⇧ Shift modifier combos (for instance ⌥ Right Option+⇧ Shift+c→⟨Ç⟩) as long as you don’t hit ⇧ Shift first.
The above answers mention ways to enter non-ascii input, but that's not really the problem here. The C-x 8 method lets you enter a bunch of non-ascii, but the problem is that you need the option key on mac just to enter the (ascii) character `|' (vertical bar)!
So how do you then enter stuff like M-| (region to shell command) when running emacs in ssh under Terminal.app? No way for it but to use the escape key, since | is option-7 and Terminal.app for some stupid reason won't let you use Cmc as meta :-(
(If anyone knows of a hack (SIMBL perhaps?) that actually does let Terminal.app use Cmd as meta, I'd be very grateful...)
The following solution works, is UNOBTRUSIVE and you don't need iTerm2 or Aquamacs or whatever.
Step 1
Keep "Use option as meta key" turned ON in the Terminal.app Settings.
Step 2
Edit ~/.inputrc (make it if it doesn't exist already), add the following line:
"\e3": '#'
This will remap ⌥ alt + 3 so that you produce a # character as expected in the terminal, instead of it annoyingly coming back with the prompt (arg: 3).
Step 3
Edit ~/.emacs, add the following line:
(global-set-key (kbd "M-3") "#")
This will remap ⌥ alt + 3 so that you produce a # character as expected inside emacs, instead of it annoyingly doing nothing.
Caveat 1, This is just 1 re-map. So ⌥ alt + ? (other keys) won't be remapped, e.g. you may wish to remap ⌥ alt + n to produce the tilde key ~. Simply follow the same steps outlined above obviously switching 3 with whichever key you need going forward.
Caveat 2, When you ssh into another box, you will face the same difficulties, but all you have to do there is edit the ~/.inputrc and ~/.emacs files on that box.
Caveat 3, I'm British, on a British MacBook. So I can't vouch for foreign MacBooks.
Aquamacs supports that, at least for my (french) keyboard. Once Aquamacs is installed (via drag'n'drop), you can go to Options -> Option, Command, Meta keys and choose an appropriate setting for your keyboard (in my case, ...Meta & French). I am not proficient with Emacs, but all the useful combinations I have tried seem to work ([, {, |, and so forth).
Supported keyboards, according to the menu items as of version 2.1, are :
British
US
Swiss-french
Swiss-german
Finnish
Italian-Pro
Italian
Spanish
French
German
I would guess the Aquamacs team would be grateful for any contribution, though, should your keyboard not appear in the list.
I bit the grass and started hitting the escape key instead. You get use to it...
I would like to mod this question up or something because i also use a Swedish keyboard where i must press alt+7 or alt+shift+7 to make | and \ respectively.
I also use Irssi in Terminal.app and these don't mix well.
I'm a long time vim user though so emacs is not an issue to me.
Isn't there some way to remap CMD to be Meta in Terminal.app?
So far i've been surviving by simply typing /wg N in Irssi because having those characters in my Terminal is much more important than IRC.
A solution would be worth gold to me though! :)
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, one that doesn't require abandoning Terminal.app in favour of iTerm 2.
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.
I assigned escape to the caps lock key and it works quite good. You can configure it easily in the mac system preferences > keyboard > modifier keys.
https://apple.stackexchange.com/a/282092/236382

Resources