Tuesday, February 4, 2014

Re: XXD with Vim

On 2014-02-04 10:50, Ven Tadipatri wrote:
> It's nice that you can go into hex mode with Vim through the use
> of XXD, but it's really hard
> trying to find out what hex codes correspond to a given character.
> Is there any kind of syntax
> highlighting, ie..if I select a particular character on the right
> side, it would highlight the
> corresponding hex value on the left side or vice versa?
> Or maybe xxd isn't meant for this. Is there some other way to
> easily view the hex representation
> of a file while also showing which hex values correspond to which
> characters?

While I don't believe there's an easy way to dynamically highlight the
character and the corresponding hex code together, you have some
options. Either you can statically color the columns to make
them easier to spot, something like this ugly one-liner:

:match Error /\(\%10c\|\%11c\|\%15c\|\%16c\|\%20c\|\%21c\|\%25c\|\%26c\|\%30c\|\%31c\|\%35c\|\%36c\|\%40c\|\%41c\|\%45c\|\%46c\|\%51c\|\%53c\|\%55c\|\%57c\|\%59c\|\%61c\|\%63c\|\%65c\)./

(it just picks out the column-numbers that should be highlighted, so
this is lazily hard-coded to 16-column xxd output format).

Or you can instruct xxd to show fewer columns to make it harder to
get lost. By default, it shows 16 columns, but sometimes 4 or 8 is
easier to work with:

xxd -c 4 file.bin > file.txt
vim file.txt
xxd -r -c 4 < file.txt > file_edited.bin

-tim




--
--
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/groups/opt_out.

No comments: