39

I've been recently learning some VIM hackery and I have learned a lot of useful commands and gotten pretty efficient at editing text with VIM. I'm using the Finnish qwerty keyboard layout (see image below) which is pretty horrible for programming. All your usual coding special characters ()[]{}/\ happen by pressing either shift or alt gr and a number key, but I'm already pretty used to that. I do not want to change my keyboard layout since I do quite a lot of writing and IRC chatting in my native language and for that I need the ä and ö characters (the å is useless for me, only the Swedes use that).

My problem is that some VIM commands have a pretty difficult keymapping by default, for example go-to-tag-under-cursor is ^] which translates to Ctrl-AltGr-9 on a Finnish keyboard. This requires me to press the left control key with my left hand, alt gr with my right thumb and extending my right index finger to the number 9 key. This feels like using emacs and/or playing classical guitar. Not exactly ergonomic.

Here's what the keyboard layout looks like:

sweden keyboard

NOTE: the keys that are marked blue are written by pressing AltGr (right alt) and the appropriate key. The red ones are two-key compose characters or dead keys which do not give out a character by them selves. F.ex. to type the ü character you first press the ¨^~ key and then u. Same goes for the accent keys. These dead keys are unmappable in VIM.

So basically I have 3 extra alphabetical keys (äöå) available, but they cannot be mapped more than once, modifier keys do not work with them (in VIM). I can map something to ä, but not Ä or <C-ä>.

Now I'm looking for ideas for my VIM setup from fellow Finnish/Swedish or other non-US keyboard layout users. Please share your key mappings, .vimrc tips and anything else that might be useful.

Emil Laine
  • 41,598
  • 9
  • 101
  • 157
exDM69
  • 2,485
  • 2
  • 15
  • 10

7 Answers7

8

I just keep the keyboard with US layout when coding and only switch to local layout (italian) when writing text that requires accented letters or other language specific characters. After all it's just a keypress to switch and nothing beats US layout for programming. I tried a bit but found that specifying lots of mappings to work around this is far more troublesome than a full layout switch on need.

Matteo Riva
  • 24,728
  • 12
  • 72
  • 104
5

My solution for this was that I made a custom keyboard layout, which combines the best aspects of the US layout into the Finnish one. The nice thing about it is that it keeps the changes to a minimum so that the learning curve is practically non-existent.

The philosophy behind it was to minimise the need to use AltGr, and still keeping it as close to the standard Fin layout as possible. And even though there are some keys under AltGr, they are all under the left hand side numbers, so you never have to press them awkwardly with your right hand while holding the modifier with your thumb.

The programs I used to make the layout were Ukelele for macOS and Microsoft Keyboard Layout Creator for Windows. I'm calling it Finner.keylayout / Finner.klc.

Here's its GitHub repo: https://github.com/ruohola/finner

Here's the basic layout (it has a lot more keys under modifiers) with the changed keys highlighted:

Image of the keylayout

ruohola
  • 21,987
  • 6
  • 62
  • 97
  • 1
    Lol, I thought I was the only one with that solution! – rickythefox Apr 17 '20 at 16:39
  • @rickythefox :D feel free to share yours also. – ruohola Apr 17 '20 at 17:18
  • 1
    I went with a similar solution: a US-based keyboard but edited to have easy access to the non-US characters I need via AltGr. I found https://www.kbdedit.com/ to be great for this and worth the few $$. – Rory Nov 29 '21 at 12:33
3

My solution is to use custom mix of US and FIN/SWE layouts. Works quite nicely(or at least better than the horrible fin layout). Image of my layout

That image probably does not have all the characters I do, but most of them anyways.

zokier
  • 143
  • 1
  • 6
2

You can use the langmap and keymap setting whtin VIM. I use it for colemak. You can specify your own layout.

h keymap
h langmap
max
  • 21
  • 1
1

As a practical stopgap, could you not simply switch between layouts?

For example, in Ubuntu, you can set up hotkeys to easily switch between layouts by going to Preferences → Keyboard → Layouts → Options → Key(s) to change layout. I use both Shift keys to quickly move between layouts, and there's even an option so that each window has its own layout setting, which works well if you're programming in Vim in a U.S. English layout while writing documentation/emails/etc. in other windows in a different layout. Even if I have to switch layouts (for code comments, etc.), it takes very little effort to hit both Shift buttons and carry on.

There should be similar ways to configure this in other desktop environments / operating systems.

gotgenes
  • 38,661
  • 28
  • 100
  • 128
  • 1
    The massive drawback is that many common shifted keys like * and < are in completely different places in the US layout. You can adjust between them with some effort but keeping track of which one you're in is now yet another distraction. (Though if you like `vim` maybe you are already conditioned to remember whether you are in insert mode or not; grumpy Emacs user here.) – tripleee Dec 15 '20 at 04:56
0

I simply have mapped those ctrl- combos to other keybindings.

For instance, ctrl-] is mapped to meta- down .

Luc Hermitte
  • 31,979
  • 7
  • 69
  • 83
  • You can actually just press `CTRL` and the `¨^~` key to get the `CTRL-]` action in Vim. It works because Vim is listening for the key codes and not the actual characters in `CTRL` sequences. – ruohola Mar 13 '19 at 12:08
  • @ruohola you're right, but this requires me to remember where `]` is located on US keyboards. I already remember the expected keybinding (`CTRL-]`), and I don't know why. Hence in the end I've chosen a keybinding that somehow makes sense in my head for jumping to the tag under the cursor, as I also have `` and `` to navigate jump locations. – Luc Hermitte Mar 13 '19 at 12:34
  • Totally understandable, just wanted to point out that the remapping is not required. I myself have solved the problem by using a custom keyboard layout as you can see from my answer. – ruohola Mar 13 '19 at 12:36
0

After using a Swedish keyboard for 25 years, with a standard Swedish layout, and actively using Vim for a few years, I was having similar thoughts to the OP's.

I had been using:

" Make some keys that are often used in normal mode more easily accessible
map å \
map ö [
map ä ]
map ¤ ^
cmap ¤ ^

for a while already, but was not too happy about the solution I had for ctrl-] and ctrl-[. I have just added:

map Ö <c-[>
map Ä <c-]>

which seems to provide a welcome improvement (contradicting one of the OP's findings as already mentioned by @ruohola).

With a Swedish layout, no solution will be perfect of course, but I think that the combination above, while modifying the defaults very little (this is one of my criteria), gives an acceptable compromise.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
nilo
  • 818
  • 8
  • 20