Mapping Alt+umlaut in .vimrc using xterm doesn't work

The following mapping doesn't work:

noremap <A-ö> :do something

I use xterm (on Ubuntu) and mappings like <A-j> work. Mapping ö alone is possible but again, <C-ö> doesn't work.

What I've tried:

  • Adding set encoding=utf-8 at the beginning of the .vimrc
  • noremap <M-ö>

Ctrl+v followed by Alt+ö in insertion mode prints ö.

Is there a way to fix this?


Solution 1:

I'm using Vim 7.4 (GUI version on Windows) and putting this in my .vimrc works for me:

" Alt-ö quits in normal mode
nmap <a-char-246> :q<cr>

" Alt-ö inserts an opening curly brace in insert mode
imap <a-char-246> {

246 is the Unicode number for ö. Here is a table for the other Unicode numbers: Link.

I tried the same commands with Ctrl instead of Alt with no success though.


Edit: As the above solution doesn't work on my current Debian system, I settled for a solution not involving Ctrl or Alt:

" Map the umlauts to be an opening parenthesis/bracket/curly brace
imap öö (
imap ää {
imap üü [

I got the idea from here. This mapping works nice for coding, especially in combination with the delimitMate plugin.

It shouldn't interfere with writing German because, as far as I know, there are no words with two consecutive umlauts. The Finns might have a hard time, though.

Solution 2:

This appears impossible because with Ctrl you get the ASCII control characters, which are defined as having a code of X-64, where X is the character you press with control (Ctrl-A is 65 - 64 = 1 = ASCII SOH and so on). But there's no ASCII code for 'Ö' to subtract from.

There's a similar scheme for Alt, which IIRC, is adding some offset like 128 instead. Mapping Alt-Ö will fail for the same reason.

Solution 3:

This does not answer your question (remapping ctrl+umlaut in .vimrc), but it might achieve what you are trying to do. You can define the keybinding not on the vim level, but on the XKB level. With Xorg XKB you can define Redirects, in this example we will remap CTRL-ö to ESC so that we can enter normal mode in vim conveniently.

Under Xorg with a german keyboard layout, try the following:

~/.xkb/keymap/vimremap (adjust to your liking, but leave the +vim(ctrloe) at the end of the xkb_symbols line)

xkb_keymap {
    xkb_keycodes  { include "evdev+aliases(qwertz)" };
    xkb_types     { include "complete"      };
    xkb_compat    { include "complete"      };
    xkb_symbols   { include "pc+de(nodeadkeys)+inet(evdev)+vim(ctrloe)"    };
    xkb_geometry  { include "pc(pc105)"     };
};

~/.xkb/symbols/vim

xkb_symbols "ctrloe" {
  replace key <AC10> {
        type= "LOCAL_EIGHT_LEVEL",
        symbols[Group1]= [      odiaeresis,      Odiaeresis,           doubleacute,   doubleacute],
        actions = [ NoAction(), NoAction(), NoAction(), NoAction(), Redirect(key=<ESC>, clearmods=all)]
  };
};

Here we are using LOCAL_EIGHT_LEVEL because this type maps Ctrl to Level5.

Now load this configuration (you can ignore the warnings about some missing symbols):

xkbcomp -I$HOME/.xkb $HOME/.xkb/keymap/vimremap $DISPLAY

Fire up xev and check if CTRL-ö indeed results in ESC.