0

Other editors I have used are able to decode URLs. For example these can take a string like this:

https://nim-lang.github.io/Nim/osproc#waitForExit%2CProcess%2Cint

and produce this:

https://nim-lang.github.io/Nim/osproc#waitForExit,Process,int

I thought about using this:

%s/%2C/,/g

but then it fails with other strings:

https://nim-lang.github.io/Nim/osproc#startProcess%2Cstring%2Cstring%2C
openArray%5Bstring%5D%2CStringTableRef%2Cset%5BProcessOption%5D

Is a better option available?

1

tpope's unimpaired plugin defines some (I think experimental) mappings for this:

ENCODING AND DECODING                           *unimpaired-encoding*

Each of these operations has a map that takes a motion, a map that
targets [count] lines, and a visual mode map.  The linewise variant integrates
with repeat.vim.

Mnemonic: encoding always comes before decoding; "[" always comes before "]".

                                                *[x* *[xx* *v_[x*
[x{motion}              XML encode.
[xx                     <foo bar="baz"> => &lt;foo bar=&quot;baz&quot;&gt;
{Visual}[x

                                                *]x* *]xx* *v_]x*
]x{motion}              XML decode.  HTML entities are handled as well.
]xx
{Visual}]x

                                                *[u* *[uu* *v_[u*
[u{motion}              URL encode.
[uu                     foo bar => foo%20bar
{Visual}[u

                                                *]u* *]uu* *v_]u*
]u{motion}              URL decode.
]uu
{Visual}]u

                                                *[y* *[yy* *v_[y*
[y{motion}              C String encode.  Backslash escape control
[yy                     characters, quotation marks, and backslashes.
{Visual}[y

                                                *]y* *]yy* *v_]y*
]y{motion}              C String decode.
]yy
{Visual}]y
0

This is a naive solution, but in general I prefer limited simple solutions to robust complicated solutions. So maybe this will be helpful to someone:

func URL_Decode()
   sub/%2C/,/ge
   sub/%3A/:/ge
   sub/%5B/[/ge
   sub/%5D/]/ge
endfunc

nmap c :call URL_Decode()<CR>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.