Rather than hand-rolling the path conversions, are you able to shell out to a command to do it? Putting aside the usual editor wars (
), I use this in my .vimrc to configure Cygwin’s Vim:
let g:opamshare = substitute(system('opam var share | cygpath -f -'),'\n$','','''')
execute "set rtp+=" . g:opamshare . "/merlin/vim"
(in Vim, the stray \r gets normalised to a stray newline)