From 90ab5eaf255983c2df2dda6b0482f8e8e3c132e0 Mon Sep 17 00:00:00 2001 From: druckdev <63563978+druckdev@users.noreply.github.com> Date: Wed, 25 Nov 2020 02:14:22 +0100 Subject: [PATCH] vim: Improve handling of German keybindings Automatically map them when setting the spelllang to de and unmap them when switching back to another language. --- .config/vim/vimrc | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/.config/vim/vimrc b/.config/vim/vimrc index f7ab003..38a999f 100644 --- a/.config/vim/vimrc +++ b/.config/vim/vimrc @@ -141,14 +141,28 @@ noremap! " Correct word with best/first suggestion. noremap c 1z= -" Umlaute and sz -map! ae ä -map! Ae Ä -map! oe ö -map! Oe Ö -map! ue ü -map! Ue Ü -map! sz ß +" Umlaute and sz in Insert and Command-line mode when spelllang is set to de +autocmd OptionSet spelllang call NewSpellLang(v:option_new, v:option_old) +function! NewSpellLang(new_lang, old_lang) + let mappings = { + \ 'ae': 'ä', + \ 'Ae': 'Ä', + \ 'oe': 'ö', + \ 'Oe': 'Ö', + \ 'ue': 'ü', + \ 'Ue': 'Ü', + \ 'sz': 'ß', + \ } + if (a:new_lang == 'de') + for [key, value] in items(mappings) + execute 'map! ' key value + endfor + elseif (a:old_lang == 'de') + for key in keys(mappings) + execute 'unmap! ' key + endfor + endif +endfunction " Jump through jump table but center noremap zz