I'm trying to use Vim as a hex editor.
I am using the %!xxd
/ %!xxd -r
method, and it worked fine until I tried a some bytes that didn't work as expected :
00000000: 1337 6161 6161 6161 6161 6161 6161 6161 .7aaaaaaaaaaaaaa
00000010: 6161 6161 6161 6161 6161 6161 6161 62ff aaaaaaaaaaaaaabR
00000020: 3713 0000 0a 7....
With this in the Vim buffer, running %!xxd -r
and then %!xxd
will produce :
00000000: 1337 6161 6161 6161 6161 6161 6161 6161 .7aaaaaaaaaaaaaa
00000010: 6161 6161 6161 6161 6161 6161 6161 62c3 aaaaaaaaaaaaaab.
00000020: bf37 1300 000a .7....
Notice the difference at the end of the second line.
Now you might think that xxd
is not used correctly, however running this : cat bytes | xxd -r | xxd
will yield :
00000000: 1337 6161 6161 6161 6161 6161 6161 6161 .7aaaaaaaaaaaaaa
00000010: 6161 6161 6161 6161 6161 6161 6161 62ff aaaaaaaaaaaaaab.
00000020: 3713 0000 0a 7....
which is what I was expecting to see in Vim.
Do you have any idea of what I am doing wrong?
\u00ff
into\xc3\xbf
, which is exactly the UTF-8 encoding of that Unicode character. So encoding is the source of the problem here. The solution might be usingvim -b
to enable binary mode (see:help 'binary'
), but not sure if that will break anything on the xxd view (since that's textual and not really binary...)