On Thu, Jun 30, 2016 at 3:45 PM, Gabriel Barta <[email protected]> wrote:
> I was using xxd to look at the hex of a utf-16le file with byte-order-mark.
> I noticed that converting from the hex form back to text just left my buffer
> empty.
>
> It seems that this is because the fileencoding causes the filter   %!xxd -r
> to pass utf-16le text to xxd.  However, xxd quite reasonably seems to expect
> the hex dump to be in ascii, (or EBCDIC!).
>
> Thinking about what vim ought to do in general for handling encoding of
> shell filters makes my head hurt!  However, at least the requirements for
> xxd are a known quantity.
>
> Although I don't know how often I will run into this problem, I have
> currently solved it for myself with the following in my vimrc:
>
> fun! s:unhexify()
>     let l:fenc = &fileencoding
>     setlocal fileencoding=latin1
>     :%!xxd -r
>     exe 'setlocal fileencoding='.l:fenc
> endfun
> com! Xxd :%!xxd
> com! XxdR :call s:unhexify()
>
>
> Is this a solid approach to the problem, and is it worth working something
> like this into the vim runtime files?
>
> - Gabriel

Which OS?

On a Unix-like OS, you might try (assuming a bash-like shell)

        LC_CTYPE=en_US.UTF-8 LC_ALL=  xxd

i.e. set the $LC_CTYPE environment variable explicitly to UTF-8 (where
codepoints U+0000 to U+007F are represented by their single-byte
US-ASCII representation) or even to Latin1 (by omitting the .UTF8
part).

Best regards,
Tony.

-- 
-- 
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui