On Wednesday, April 22, 2015 at 8:06:18 AM UTC-5, Igor Forca wrote:
> Hi,
> I am using gVim 7.4 on Windows 7. I would like to encode ASCII text into BASE64 text.
>
> 1. First I have set code page to UTF-8 and file format to unix.
> :set encoding=utf-8
> :set fencoding=utf-8
> :set fileformat=unix
>
I think, you will also need to set termencoding to match. This is the encoding Vim will use when it sends bytes to external commands. You don't want any conversion done between what Vim has and what Vim sends, in this case.
> 2. Then I have typed in text: Man
> This is the sample from: https://en.wikipedia.org/wiki/Base64#Examples
> 3. Saved to file: :w
> 4. Converted text from ASCII to BASE64:
> :%!base64
> and text Man is converted into:
> TWFuCg==
> This is not correct. Why? The mail logic: three ASCII character should be converted into 4 BASE64 characters, but I get 8 characters as BASE64 output.
>
> Man should be converted into:
> TWFu
>
> This can also be verified with: https://www.base64encode.org/ typing Man in top input box and click on Encode.
>
> What I suspect is that Vim is also converting Line Feed character (the last character in the line). Why? Type in:
> Man
> and execute command:
> :%!xxd and output is hex number of Man characters:
> 4d616e0a
>
> [snip]
>
> If I am correct and Vim does include Line Feed character when converting text from ASCII to BASE64, then:
> a) Is there a way to convert from ASCII to BASE64 without line feed character.
> b) Is there a way to remove line feed character from end of line in Vim? So when converted it will not get included into conversion.
>
I think you're correct. Here's how to prevent that:
:setlocal binary noeol
Now when you save or use an external command, no line ending will be added by Vim for the last line (in your case, the only line).
See :help 'eol' and :help 'binary' and http://vim.wikia.com/wiki/Preserve_missing_end-of-line_at_end_of_text_files
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment