map :call Eng2Ger(expand("")) map :call Ger2Eng() let dictpath = '~/Kram/eng2ger.vok' let vocpath = '~/Kram/vimvoc.txt' function Ger2Eng() let word = inputdialog("Übersetze de -> eng: ") call Extract(word, "want_eng") endfunction function Eng2Ger(word) let word = a:word call Extract(word, "want_ger") endfunction function Extract(word, lang) let word = a:word let lang = a:lang let wordpair = system('grep "^' . word . '\b \-\|\- \b'. word . '$" ' . g:dictpath) if(v:shell_error) echohl ErrorMsg echo "Fehler aufgetreten!" echohl None else let match = matchstr(wordpair, "[^\n]*") call Translate(match, word, lang) endif endfunction function Translate(match, word, lang) let match = a:match let word = a:word let lang = a:lang if(lang == "want_eng") let result = substitute(match, "\\(" . word . "\\) -- ", submatch(1), "") call ConfirmDialog(result, match) elseif(lang == "want_ger") let result = substitute(match, " -- \\(" . word . "\\)", submatch(1), "") call ConfirmDialog(result, match) endif endfunction function ConfirmDialog(result, match) let result = a:result let match = a:match let choice = confirm(result, "&Insert\n&Save to File\n&Cancel", 3, "Question") if(choice == 1) execute "normal ea " . result elseif(choice == 2) execute "e " . g:vocpath execute "normal o" . match execute "w" . g:vocpath . "|bd" elseif(choice == 3) execute "normal e" endif endfunction