Created
May 19, 2017 16:35
-
-
Save atripes/15372281209daf5678cded1d410e6c16 to your computer and use it in GitHub Desktop.
URL encode/decode vim selection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" URL encode/decode selection | |
vnoremap <leader>en :!python -c 'import sys,urllib;print urllib.quote(sys.stdin.read().strip())'<cr> | |
vnoremap <leader>de :!python -c 'import sys,urllib;print urllib.unquote(sys.stdin.read().strip())'<cr> |
Thanks! What do you use instead now?
The solution I use now is:
function! EncodeURIComponent() range
let saved_reg = @"
normal! gvy
let selected_text = @"
let encoded = system('node -e "process.stdout.write(encodeURIComponent(process.argv[1]))" -- ' . shellescape(selected_text))
let @" = encoded
normal! gv"_d"0P
let @" = saved_reg
endfunction
vnoremap <leader>ue :call EncodeURIComponent()<CR>
Interesting use case you got there of internet searching something from a buffer. That is pretty neat.
I just wanted to be able to write text fragment links which need to be url-encoded.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oi vim friends!
I have stopped using vim for some time now. Having said that @unphased here's a sample
xnoremap
usage for a function that usesUrlEncode
: https://github.com/Bhupesh-V/.Varshney/blob/master/init.vim#L148