Johannes Schwarz wrote:
Is there a builtin url-encoding function available in vim?
Or has s.o. wrote a script already?

Do you mean something like this (based on code from eval.txt):

fun! EncodeChar(char)
    if a:char == '%'
        return '%%'
    elseif a:char == ' '
        return '+'
    else
        " Taken from eval.txt
        let n = char2nr(a:char)
        let r = ''
        while n
            let r = '0123456789ABCDEF'[n % 16] . r
            let n = n / 16
        endwhile
        return '%'. r
    endif
endf

fun! EncodeURL(url)
    return substitute(a:url, '\([^a-zA-Z0-9_.-]\)', 
'\=EncodeChar(submatch(1))', 'g')
endf

Cheers,
Thomas.

Reply via email to