Ecco uno script che utilizza Python e il modulo base64
per fornire base64 decodificare e enc comandi di ode Sarebbe piuttosto semplice supportare qualsiasi altro programma base64, purché risulti dallo stdin - basta sostituire python -m base64 -e
con il comando di codifica e python -m base64 -d
con il comando di decodifica.
function! Base64Encode() range
" go to first line, last line, delete into @b, insert text
" note the substitute() call to join the b64 into one line
" this lets `:Base64Encode | Base64Decode` work without modifying the text
" at all, regardless of line length -- although that particular command is
" useless, lossless editing is a plus
exe "normal! " . a:firstline . "GV" . a:lastline . "G"
\ . "\"bdO0\<C-d>\<C-r>\<C-o>"
\ . "=substitute(system('python -m base64 -e', @b), "
\ . "'\\n', '', 'g')\<CR>\<ESC>"
endfunction
function! Base64Decode() range
let l:join = "\"bc"
if a:firstline != a:lastline
" gJ exits vis mode so we need a cc to change two lines
let l:join = "gJ" . l:join . "c"
endif
exe "normal! " . a:firstline . "GV" . a:lastline . "G" . l:join
\ . "0\<C-d>\<C-r>\<C-o>"
\ . "=system('python -m base64 -d', @b)\<CR>\<BS>\<ESC>"
endfunction
command! -nargs=0 -range -bar Base64Encode <line1>,<line2>call Base64Encode()
command! -nargs=0 -range -bar Base64Decode <line1>,<line2>call Base64Decode()
Alcune caratteristiche questo prevede:
Supporta gamme, converte solo la linea corrente di default (utilizzare :%Base64Encode
per codificare l'intero file, per esempio, e che funzionerà come previsto dal di dentro modalità visiva, anche se converte solo intere righe)
Non lascia l'output rientrato: tutti i rientri (tabulazioni/spazi) sono codificati in base64 e quindi conservati durante la decodifica.
supporti essendo in combinazione con altri comandi con |
rilevanti :help
tags: user-functions
, func-range
, i_0_CTRL-D
, i_CTRL-R_CTRL-O
, expr-register
, system()
, user-commands
, command-nargs
, command-range
, :normal
Vuoi sostituire il testo selezionato? –
La sostituzione sarebbe OK, anche l'output normale alla console sarebbe OK. – Jonatan