4

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?

mkrnr
  • 842
  • 8
  • 17

3 Answers3

5

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.

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
  • How do you then use the jump-link functions that use `CTRL-]` in the default vim config? – jaaq Apr 03 '19 at 15:45
  • @jaaq: I chose another route: I switched to US keyboard layout by configuring my OS and removed the mappings in this answer from vimrc. Now, I insert umlauts (and other characters outside the US layout) using Vim's [digraph feature](https://vim-jp.org/vimdoc-en/digraph.html): `c-k o:` → ö, `c-k A:` → Ä, `c-k ss` → ß – Matthias Braun Apr 03 '19 at 16:23
  • well if I use an US keyboard, all these problems go away anyway. During programming I never need character present on a german keyboard anyway. Is there a way to reconfigure how to execute vim commants instead? I'd rather reconfigure `CTRL-]` to e.g. `CTRL-ö` than switch to an english keyboard. this could be used in parallel to mapping the unused umlauts to brackets and would be nicer to use as well imho. – jaaq Apr 05 '19 at 10:07
  • @jaaq: Consider posting a separate question where you detail how you want to reconfigure Vim. – Matthias Braun Apr 05 '19 at 11:24
  • good idea! will do, once I started to understand the philosophy of vim, before I break the way it's intended to be used. – jaaq Apr 05 '19 at 14:45
  • 1
    Great, @jaaq, have fun! Depending on where you are on your Vim journey, you might find these resources helpful: [`vimtutor`](https://alvinalexander.com/linux/learn-vi-vim-tutorial-vimtutor-help), [Seven Habits of Effective Text Editing](https://www.moolenaar.net/habits.html), [Modern Vim](https://pragprog.com/book/modvim/modern-vim), [Vim Galore](https://github.com/mhinz/vim-galore). Vimify Firefox: [vim-vixen](https://addons.mozilla.org/en-US/firefox/addon/vim-vixen/), [withExEditor](https://addons.mozilla.org/en-US/firefox/addon/withexeditor/). – Matthias Braun Apr 07 '19 at 10:08
  • I posted a [followup-question](https://softwarerecs.stackexchange.com/q/58089/47679); I'd love further input. I could use some direction from an experienced vim user- to quickly get into using vim as an IDE, since I'll be forced to work without the IDEs I am used to rather soon so making the switch now makes sense. – jaaq Apr 11 '19 at 15:38
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.

Jens
  • 69,818
  • 15
  • 125
  • 179
1

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.

PiQuer
  • 2,383
  • 25
  • 29