How do I remap META to ALT? - emacs

I am using emacs in Ubuntu. How can I remap META to the ALT key?

If you run emacs in a gnome-terminal, the gnome-terminal may be capturing your alt key to open the gui menu (File, Edit, ...). You can change this behavior by selecting Edit >> Keyboard Shortcuts ..., and unchecking `Enable menu access keys ...'.
On my system, Ubuntu 9.04, this lets alt serve as meta for emacs.

Usually Meta is mapped to the Alt key by default.
What is displayed in the echo area at the bottom of the Emacs window when you type Alt+X? If you see M-x then Alt is working as Meta.

Way back when, it did seem that the META key was difficult to map to the ALT. At that time I had to use xmodmap, and these were the things I had to put in my .xmodmap file. Some variation of the following always worked (it depended on the system). My .xinitrc file would have xmodmap read in the file.
!! Note the `!` are comment characters.
!! suggested to make Emacs work under VNC
keysym Alt_L = Meta_L
keysym Alt_R = Meta_R
!! xmodmap -e 'keysym Alt_L = Meta_L' -e 'keysym Alt_R = Meta_R'
!!
!! some environments still can't handle alt key properly
!! add this:
!!
clear Mod1
add Mod1 = Meta_L Meta_R
!! or
!! xmodmap -e "clear Mod1" -e "add Mod1 = Meta_L Meta_R"

Use xkeycaps to look at your keyboard mapping and swap the META and ALT modifiers, or just swap the entire keys. Because GNOME has some assumptions about which keys have META and ALT modifiers, it'll probably make your life easier to swap the keys entirely.
xkeycaps should be available as an ubuntu package.

If using a Mac, open up terminal then navigate to Terminal > Preferences. Under the profiles tab, check the checkbox on Use Option as Meta Key. See screenshot
That should do the trick.

Related

IdeaVim: Make Cmd-A (macOS) select all text in visual mode

I want Cmd-A (the macOS Command key, plus A) to select all text in visual mode, so I can e.g. indent or delete it using vim commands, Just like it does in MacVim. By default, it selects all text, but vim commands don't work on it.
I've put the following in .ideavimrc:
map <D-a> <esc>ggVG
And also removed the default Cmd-A shortcut in Preferences -> Keymap, because it seemed to override the vim one. But now Cmd-A just doesn't do anything.
I've found two workarounds so far, neither very satisfying. For both start out in normal-mode.
ggVG
press v followed by Cmd-A
<D-*> mappings are not supported in IdeaVim yet. Feel free to vote for VIM-758 and contribute a fix to https://github.com/JetBrains/ideavim.
Edit: You can check your effective mappings in IdeaVim via :map.
Edit 2: I've checked <M-*> mappings in IdeaVim 0.50 in macOS. They do exactly what you want, but with <M-*> instead of <D-*>. In my experiment, I've remapped dd to Command-A via:
map <M-a> dd
Important: the first time you open the IDE afterwards, there is a notification: "Using the shortcut from vim emulation. etc." Do not click the link in that notification, otherwise it will not use your shortcut defined in .ideavimrc.

Use Alt key as Meta in emacs

Somehow the emacs I'm using doesn't treat Alt as Meta. It only uses ESC for it. If I press Alt+x it will tell me "A-X" undefined. I tried to figure out how to map it to meta but got no luck on the web because in most of results from my search people take Alt as Meta by default. I guess something like this should work:
global-set-key Alt(?) 'meta
but I'm not sure how to represent Alt in lisp.. any help? Thanks!
Most solutions will tell you to change keymap at the X11 level. The wiki suffers from the problem of too much information. If you just want a solution that works only at the emacs level (quite useful for VNC/remote desktop), then add the below line to your emacs init file
;; Map Alt key to Meta
(setq x-alt-keysym 'meta)
I had the same problem and by putting this in ~/.emacs helped me.
(set-keyboard-coding-system nil)
Refer to this, if you need more help
http://www.emacswiki.org/emacs/MetaKeyProblems#toc15
Entering this command in a shell (even M-x shell) works for me.
xmodmap -e "clear mod4"
This works when the problem is that the output of xmodmap includes a line showing that Meta_L is set to mod4:
mod4 Meta_L (0x73)
Emacs thinks your keyboard has a Meta key, so it's not interpreting Alt as Meta. The above command tells X that you don't have a Meta key, so Emacs will interpret Alt the way that we're used to.
I learned this from https://www.emacswiki.org/emacs/MetaKeyProblems.

Alt key not working in Emacs SSHing X11

Hello this isn't a coding question but...
I ssh through my mac using X11, and I am using emacs. I am trying to use the "ALT" key for combination but it seems to not be working. I have tried using the "option" key, and "FN + option" both seems to not work.
I had the same problem before. The hint on http://hints.macworld.com/article.php?story=20040425231058862 helps me.
To summarize, you should use xmodmap to remap alt / option in X11.
Put the following in your ~/.Xmodmap file:
clear Mod1
keycode 66 = Meta_L
add Mod1 = Meta_L
If the emacs instance is somewhere else, which is how I read your question, then it maybe that emacs isn't receiving the correct key when you press alt.
There are a variety of fixes on http://www.emacswiki.org/emacs/EmacsForMacOS#toc20.
However, I'd say that you're probably approaching the problem from the wrong direction. Have you considered running emacs locally, and using TRAMP mode edit the remote files on the local machine?
try putting this in ~/.emacs
(set-keyboard-coding-system nil)

Right ALT key not working as meta key in emacs

I have launched emacs (emacs -Q) in the console(Ctrl+Alt+F1). The "left Alt key" is
working whereas the "right Alt key" is not working. How to fix the problem. I am running emacs on archlinux
This behavior is controlled by the keyboard layout you are using. In the layout that you are using, the left alt is Meta, whereas the right alt is Alt-graphic which allows you to enter accentuated character. Change your keyboard layout to one not using the right alt as Alt-graphic
The solution is described here:
http://www.joshstaiger.org/archives/2005/04/fixing_the_righ.html
It needs some modifications though (see item 3.2 below).
Otherwise one would not be able to type anything in current console after the first press of [Right Alt].
If this happened to you, switch to other console (e.g. [Ctrl+Alt+F2]) and restore old keymap.
Here is the brief description of the modified solution:
Save current keymap to file:
dumpkeys >> mykmap
and make a backup of it:
cp mykmap oldkmap
Capture [Right Alt] keycode using showkey command. Let's assume it is 100.
Edit mykmap:
Find the corresponding line:
keycode 100 = AltGr
and change it to:
keycode 100 = Alt
If the next line (or one of the next lines) is:
alt keycode 100 = Compose
remove it.
Load new keymap:
loadkeys mykmap
Make the changes permanent (e.g. add the last command to ~/.bashrc).

M-RET and M-UP/DOWN not working in Emacs org-mode in console/terminal

I'm using emacs23 on Ubuntu 32-bit 10.04/10.10 with GNOME and Compiz.
Pressing M-RET in an org-mode plain list in Emacs (GUI) inserts a new item. Pressing M-Up moves the item up in the list.
These keys don't work as expected in emacs -nw under Terminator and gnome-terminal. The M-Up key does nothing, whereas the M-RET key simply moves the cursor down one line and indents the position. The keys also don't "work" in xterm, which inserts \215 instead. Pressing ESC-RET or ESC-Up instead produces the expected functionality. The same problems exist if I run emacs -nw on a headless server accessed via ssh under Terminator, gnome-terminal and xterm.
I've searched both generally and on the org-mode Gmane list for an answer to this, but have not found anything. Is this a known issue with org-mode or is it related to the terminal emulator and/or the Window Manager?
In addition to the keys in my question, S-TAB, S-Left, S-Right, S-Up and S-Down were not working over ssh and PuTTY. Using certain keys on a TTY connection (ssh, screen, PuTTY) is a known issue.
Alternative keys are included in org-mode as detailed in 'Using Org on a TTY' in the org-mode manual.
Alternative key combinations exist
for equivalent to M-RET
M C-m
"<return>" is the Return ↩ key while emacs runs in a graphical user interface.
"RET" is the Return ↩ key while emacs runs in a terminal.
"RET" is also equivalent to "C-m" (【Ctrl+m】). (http://ergoemacs.org/emacs/emacs_key_notation_return_vs_RET.html)
as equivalents for M-<up/down> you can use
ESC-<up>
ESC-<down>
The menubar of terminal emulator is not letting the M key that is meant for Emacs be passed down to Emacs. For Emacs to receive the M key as it is supposed to, you could either use the Esc or disable the menubar and use M key in Emacs as usual.
ADDED:
For the xterm, if you do CTRL+Mouse Button 1, you will see "Meta sends Escape". You need to make sure that option is checked/enabled to make M work as it should in Emacs.