added base64 decode and encode through leader be and leader bd

This commit is contained in:
Stefan Friese 2024-09-18 09:51:39 +00:00
parent fa90dec208
commit 031f2d876b
1 changed files with 21 additions and 0 deletions

View File

@ -336,3 +336,24 @@ let g:fzf_colors =
\ 'marker': ['fg', 'Keyword'], \ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'], \ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] } \ 'header': ['fg', 'Comment'] }
" xnoremap <leader>c <esc>=:'<,'>:w ! base64<C-M>p
" Function to base64 encode the exact selected text and replace it without a newline
function! Base64EncodeSelection()
normal! gv"vy
let l:selected_text = getreg('"')
let l:encoded_text = system('echo -n ' . shellescape(l:selected_text) . ' | base64 -w0')
let l:encoded_text = trim(l:encoded_text)
execute "normal! gv\"_c" . l:encoded_text
endfunction
xnoremap <leader>be :<C-u>call Base64EncodeSelection()<CR>
function! Base64DecodeSelection()
normal! gv"vy
let l:selected_text = getreg('"')
let l:encoded_text = system('echo -n ' . shellescape(l:selected_text) . ' | base64 -d')
let l:encoded_text = trim(l:encoded_text)
execute "normal! gv\"_c" . l:encoded_text
endfunction
xnoremap <leader>bd :<C-u>call Base64DecodeSelection()<CR>