From 935caedb1686361c600938787f8b78983e6cc689 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Sun, 27 Sep 2020 01:09:25 +0100 Subject: [PATCH] VIM: adds hex encoding and decoding --- nvim/.config/nvim/autoload/mine/encoding.vim | 13 +++++++++++++ nvim/.config/nvim/plugin/mappings.vim | 2 ++ 2 files changed, 15 insertions(+) diff --git a/nvim/.config/nvim/autoload/mine/encoding.vim b/nvim/.config/nvim/autoload/mine/encoding.vim index 742e0b25..8a0b5ab3 100644 --- a/nvim/.config/nvim/autoload/mine/encoding.vim +++ b/nvim/.config/nvim/autoload/mine/encoding.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 diff --git a/nvim/.config/nvim/plugin/mappings.vim b/nvim/.config/nvim/plugin/mappings.vim index 4dd7267a..b2f73671 100644 --- a/nvim/.config/nvim/plugin/mappings.vim +++ b/nvim/.config/nvim/plugin/mappings.vim @@ -50,3 +50,5 @@ vnoremap [u :call mine#encoding#wrapper('urlEncode') vnoremap ]u :call mine#encoding#wrapper('urlDecode') vnoremap [U :call mine#encoding#wrapper('urlEncodeAll') vnoremap ]U :call mine#encoding#wrapper('urlDecode') +vnoremap [h :call mine#encoding#wrapper('hexEncode') +vnoremap ]h :call mine#encoding#wrapper('hexDecode')