Vim With Norwegian Keyboard

3 minute read Published:

Improving the use of a norwegian keyboard with vim

I have been writing a lot of code, lately, I have been writing C, C++ and GO. All these languages have 6 characters in common {} () and ;. I use vim, you might have seen my guide to neovim on windows previously. Vim also uses {} and () for navigation. If we look at an American keyboard this makes a lot of sense: US keyboard

So why is that so awesome? well the keys for {} and () is right next to hjkl, the primary navigation keys in vim. As an avid user of the touch method of typing vim has tons of super nice features, making it so that i never have to take my hands of the keyboard.

In Norwegian however we have 3 special characters æøå, and they change everything. Why? look at this image: NO Keyboard

So the {}, [] and () keys are moved to 7 8 9 and 0, Because æøå need their space. In addition, the ALTGR or commonly left alt needs to be pressed at the same time. C programming becomes slightly less fun because of it, also sentence and paragraph movement in vim becomes significantly more difficult.

I have therefore added some things to my vimrc:

"
"   NORWEGIAN KEYBOARD MODS
"

"NORMAL
nnoremap ø (
nnoremap æ )
nnoremap Ø {
nnoremap Æ }
nnoremap å 0
nnoremap Å $

nnoremap <A-æ> æ
nnoremap <A-ø> ø
nnoremap <A-Æ> Æ
nnoremap <A-Ø> Ø

"VISUAL
vnoremap ø (
vnoremap æ )
vnoremap Ø {
vnoremap Æ }
vnoremap å \
vnoremap Å `

vnoremap <A-æ> æ
vnoremap <A-ø> ø
vnoremap <A-Æ> Æ
vnoremap <A-Ø> Ø

"REPLACE
lnoremap ø (
lnoremap æ )
lnoremap Ø {
lnoremap Æ }
lnoremap å \
lnoremap Å `

"INSERT
inoremap ø (
inoremap æ )
inoremap Ø {
inoremap Æ }
inoremap <A-æ> ]
inoremap <A-ø> [
inoremap å \
inoremap Å `

inoremap <A-e> æ
inoremap <A-o> ø
inoremap <A-E> Æ
inoremap <A-O> Ø
inoremap <A-a> å
inoremap <A-A> Å

inoremap <C-æ> æ
inoremap <C-ø> ø
inoremap <C-Æ> Æ
inoremap <C-Ø> Ø

This makes it so that the æ and ø buttons now are { and } Æ and Ø is now ( and ), adding in alt gives us [ and ]. But what about ø and æ? well alt and a gives å and å gives å, alt and o gives ø, alt and e gives æ. These characters are used by me so seldom when I program that the biggest difficulty I have had with this system was the current blog post. I hope it helps fellow Norwegian programmers.