I recently came over some use for letters like æ, ø, and å. For context, these are available on my keyboard, and work fine in other programs. It's also a Norwegian keyboard if that's relevant.

With Vim, specifically gVim, only æ and ø work. Other combined letters (such as ö and â work out of the box (by typing ¨o). Attempting to write å results in various behavior I can't understand (with no remapping, pressing it shifts around lines or letters. Typing it in an empty buffer with no remapping pulls code from somewhere, possibly a swap file?).

I know I can type the letter with <C-v> (as suggested here) or with <C-k> å å, but this is slow and, in my opinion, unnecessary. Also, <C-v> å results in å, so I'm assuming I'm supposed to use it when attempting to remap.

I tried with imap å <C-v> å, imap å <C-k>å, imap å <C-k> å, imap å <C-k> å å, imap å <C-k> åå, and the basic imap å å, but none of them give me the letter. Remapping it to other output letters doesn't do anything at all (one of the other variants listed here resulted in an e).

How do I remap the key å to actually give me the letter å in insert mode?

When I haven't messed around with mapping, :verbose map å says the key isn't used.

  • 1
    :verbose map shows the mappings for normal, visual, select, and operator-pending mode. For insert mode mappings you need to use :verbose imap or :verbose map! (see :help map-modes). Aug 26 '19 at 9:43
  • 1
    @JürgenKrämer Right, I keep mixing those up ^^" å was actually remapped by a plugin (github.com/jiangmiao/auto-pairs). For a quick hackish test, disabling it fixed the letter, so I'll just have to see if I can avoid that specific mapping with some config. Also, does it make sense to keep the question or should I just delete it?
    – Zoe
    Aug 26 '19 at 9:50
  • 2
    @Zoe You should self-answer, indicate how you found the mapping existed and how you found which plug-in set the mapping. If you find more about how it set it and why, include that in your answer as well...
    – filbranden
    Aug 26 '19 at 10:04
  • Done. Thanks again ^^
    – Zoe
    Aug 26 '19 at 12:29
  • 1
    Thank you @Zoe for digging into this and writing such a detailed answer!
    – filbranden
    Aug 26 '19 at 16:08

I screwed up slightly on which :verbose map to use. Since it's while editing, and the relevant mapping is imap or inoremap, :verbose imap/:verbose map! would be the right command.

In this case, the reason I had such weird behavior is because of the function it's mapped to. It calls a function in a parentheses auto-completion/utility plugin, and specifically the fast wrap feature (which wraps words in parentheses - I haven't used that feature much).

Running :verbose imap å or :verbose map! å gave me this:

i  å           *@<C-R>=AutoPairsFastWrap()<CR>
    Last set from ~\.vim\plugged\auto-pairs\plugin\auto-pairs.vim line 562

In this case, the plugin used is jiangmiao/auto-pairs. The block that set the shortcut looks like this:

if g:AutoPairsShortcutFastWrap != ''
  execute 'inoremap <buffer> <silent> '.g:AutoPairsShortcutFastWrap.' <C-R>=AutoPairsFastWrap()<CR>'

By default, the shortcut is set to <M-e>, but that in itself doesn't necessarily make sense, especially with the mapping. If, however, you type <M-e> when it's not remapped, it outputs å. <C-v> <M-e> also gives å this might be keyboard-dependent - I'm not sure and I can't test it. So the plugin remapping <M-e> resulted in å being remapped to a function that when provided sensible input works fine, but when provided none or invalid input results in the weird behavior I saw.

The reason I couldn't override it is because the original remapping was done with <buffer>, which seems to override the global ones. I think that's the reason imap å å didn't work. With imap <buffer> å å, it outputs å instead of calling the plugin functon that originally defined it.

That being said, there's a relatively easy fix to this that doesn't require any remapping of å, but rather remapping the plugin. The code I showed earlier uses g:AutoPairsShortcutFastWrap, which defines which key it'll map to. I just decided on <C-f>, but any unused shortcut will do:

let g:AutoPairsShortcutFastWrap = "<C-f>"

After reloading Vim, å works as a normal letter again.

TL;DR: <M-e> is å (<C-v> <M-e> gives me å at least), jiangmiao/auto-pairs remapped <M-e>, which affected the å key as well. There is most likely other mappings that are equivalent to other non-English letters as well, which can explain what happens when similar keys break on other keyboards.

  • 1
    It sounds like either you have a broken terminal with "bit8meta", i.e. alt+key produces a single byte that's 0x80|key, or vim is configured to expect such a terminal. This is a backwards convention from the 80s that's complely incompatible with non-ascii text and should have been removed from everything that supported it at least 2 decades ago, but of course it wasn't. The correct behavior for the meta (alt) key is to generate Esc followed by the key. Alternatively it could generate the UTF-8 form of C1 control characters, but nobody does that. Aug 26 '19 at 21:48
  • @R.. I'm using gvim (see the tags - also running 8.1). If that's relevant, I set the charset to utf-8. Not sure if I've somehow configured it to expect bit8meta, but I at least haven't done that intentionally. It could be that gvim somehow interprets it as the letter due to some weird implementation. I actually have some other things Vim does that I can't do elsewhere without some form of markdown/rendering (like Unicode sup numbers). Dunno though. I'll see if I can repro on a Linux install (freshly installed today) using gvim and terminal Vim, and see if my config somehow makes a difference.
    – Zoe
    Aug 26 '19 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.