をデコードするためのF3は、ここでbase64でデコードおよびENCを提供するために、Pythonのスクリプトを使用してbase64
モジュールですodeコマンド。 stdinから読み込むのであれば、他のbase64プログラムもサポートするのは簡単でしょう。python -m base64 -e
をencodingコマンドで置き換え、python -m base64 -d
をdecodingコマンドで置き換えてください。
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()
一部の機能これが用意されています
関連:help
タグを有する他のコマンドと組み合わせをサポートしている:user-functions
、func-range
、i_0_CTRL-D
、i_CTRL-R_CTRL-O
、expr-register
、system()
、user-commands
、command-nargs
、command-range
、:normal
あなたがしたいですか選択したテキストを置き換えますか? –
置き換えても問題ありません。コンソールへの普通の出力もOKです。 – Jonatan