VIM: adds hex encoding and decoding

Jonathan Hodgson 4 years ago
parent 380e2c81c8
commit 935caedb16
  1. 13
      nvim/.config/nvim/autoload/mine/encoding.vim
  2. 2
      nvim/.config/nvim/plugin/mappings.vim

@ -12,6 +12,19 @@ function! mine#encoding#base64Decode(text) abort
return substitute(system('base64 --decode --ignore-garbage --wrap=0', a:text), '\n$', '', 'g')
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
" Taken from https://github.com/tpope/vim-unimpaired/blob/master/plugin/unimpaired.vim
function! mine#encoding#urlEncode(text) abort

@ -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('urlEncodeAll')<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>

Loading…
Cancel
Save