VIM: adds hex encoding and decoding

This commit is contained in:
Jonathan Hodgson 2020-09-27 01:09:25 +01:00
parent c94fb3a761
commit be84812aaa
2 changed files with 15 additions and 0 deletions

View file

@ -12,6 +12,19 @@ function! mine#encoding#base64Decode(text) abort
return substitute(system('base64 --decode --ignore-garbage --wrap=0', a:text), '\n$', '', 'g') return substitute(system('base64 --decode --ignore-garbage --wrap=0', a:text), '\n$', '', 'g')
endfunction endfunction
" hex encodes text
" It relies on the executable xxd
function! mine#encoding#hexEncode(text) abort
return substitute(system('xxd -p', a:text), '\n$', '', 'g')
endfunction
" base64 decodes text
" It relies on the executable base64 which should be installed on most unix-y
" systems.
function! mine#encoding#hexDecode(text) abort
return substitute(system('xxd -r -p', a:text), '\n$', '', 'g')
endfunction
" Url encodes characters that are normally encoded in urls " Url encodes characters that are normally encoded in urls
" Taken from https://github.com/tpope/vim-unimpaired/blob/master/plugin/unimpaired.vim " Taken from https://github.com/tpope/vim-unimpaired/blob/master/plugin/unimpaired.vim
function! mine#encoding#urlEncode(text) abort function! mine#encoding#urlEncode(text) abort

View file

@ -50,3 +50,5 @@ vnoremap [u :call mine#encoding#wrapper('urlEncode')<cr>
vnoremap ]u :call mine#encoding#wrapper('urlDecode')<cr> vnoremap ]u :call mine#encoding#wrapper('urlDecode')<cr>
vnoremap [U :call mine#encoding#wrapper('urlEncodeAll')<cr> vnoremap [U :call mine#encoding#wrapper('urlEncodeAll')<cr>
vnoremap ]U :call mine#encoding#wrapper('urlDecode')<cr> vnoremap ]U :call mine#encoding#wrapper('urlDecode')<cr>
vnoremap [h :call mine#encoding#wrapper('hexEncode')<cr>
vnoremap ]h :call mine#encoding#wrapper('hexDecode')<cr>