A.J.Mechelynck schrieb:
[EMAIL PROTECTED] wrote:
Hi,
I want to write a macro, function or what else, which ensures, that
no german umlauts (äöüÄÖÜ) or the "sz" (ß) will ever occure in any
file written with vim. It does not matter, if these charactes will
appear while typing but they should never and under no circumstances
be saved to disk. Best solution however would be, if they were
changed "on the fly" to their replacements:
umlaut a ä -> ae
umlaut o ö -> oe
umlaut u ü -> ue
umlaut A Ä -> Ae
umlaut O Ö -> Oe
umlaut U Ü -> Ue
"sz" ß -> sz
I did some experiments, which had worked under some circumstances and
did not under others.
But I need something, which does the replacements under any
condition.
Keep editing!
mcc
just another variant ...
Method I: will remove all umlauts in all files, even preexisting ones
(if any) at write-time.
scriptenc latin1
function ConvertUmlauts()
" range is whole file
let udict = {'ä':'ae', 'ö':'oe', 'ü':'ue',
\'Ä':'Ae', 'Ö':'Oe', 'Ü':'Ue',
\'ß':'sz'}
%s/[äöüÄÖÜß]/\=udict[submatch(0)]/ge
endfunction
autocmd BufWritePre * call ConvertUmlauts()
Method II: will remove umlauts only as you type them. Anything
preexisting will remain untouched.
Method II a) use a keymap
:h :lmap
(keymaps use :lmap to define mappings)
File ~/.vim/keymap/umlauts.vim
" Vim Keymap
scriptenc latin1
let b:keymap_name="de_uml"
loadkeymap
ä ae
ö oe
ü ue
Ä Ae
Ö Oe
Ü Ue
ß sz
Argument of :scriptenc is at your taste/needs, I just suggest to
not skip the command because of the non-ascii chars.
Load the keymap:
:set keymap=umlauts
Toggle keymap on/off:
:h i_Ctrl-^
From the help:
":lmap" defines a mapping that applies to:
Insert mode, Command-line mode, when entering a search pattern,
commands with a character argument (r, f) (won't probably work here),
and for the input() line.
These two solutions are not exclusive of each other: they can be applied
together.
Note that the official transliteration of the eszett is not sz but ss:
upcase("ß") is "SS" and, in de_CH locales, the eszett is not used (other
than for "archaic" look, sometimes together with a Fraktur font); ss is
used in its stead everywhere.
IMHO "sz" is ugly, but unique. There is no upper "ß".
Best regards,
Tony.
--
Regards,
Andy
EOM