यहाँ डिकोड करने के लिए एक स्क्रिप्ट अजगर और base64
मॉड्यूल का उपयोग करता है base64 डिकोड और ENC प्रदान करने के लिए है स्तोत्र आदेशों। यह बहुत किसी अन्य बेस 64 कार्यक्रम का समर्थन करने के साथ ही सरल, जब तक कि यह stdin से पढ़ता होगा - बस डिकोडिंग कमांड के साथ एन्कोडिंग कमांड के साथ python -m base64 -e
और python -m base64 -d
बदलें।
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()
कुछ सुविधाएं इस प्रदान करता है:
पर्वतमाला का समर्थन करता है, डिफ़ॉल्ट (:%Base64Encode
का उपयोग उदाहरण के लिए पूरी फ़ाइल एन्कोड करने के लिए, द्वारा केवल वर्तमान लाइन बदल देता है, और यह के भीतर से अपेक्षा के अनुरूप काम करेंगे दृश्य मोड, हालांकि यह केवल पूरी लाइनों को परिवर्तित करता है)
आउटपुट इंडेंट नहीं छोड़ता है - सभी इंडेंट्स (टैब/रिक्त स्थान) को बेस 64 में एन्कोड किया जाता है, और फिर डीकोडिंग के दौरान संरक्षित किया जाता है।
|
प्रासंगिक :help
टैग के साथ अन्य आदेशों के साथ संयुक्त किया जा रहा समर्थन करता है: user-functions
, func-range
, i_0_CTRL-D
, i_CTRL-R_CTRL-O
, expr-register
, system()
, user-commands
, command-nargs
, command-range
, :normal
आप करना चाहते हैं चयनित पाठ को प्रतिस्थापित करें? –
प्रतिस्थापन ठीक होगा, कंसोल के लिए सादे आउटपुट ठीक भी होगा। – Jonatan