XXD with Vim

343 views
Skip to first unread message

Ven Tadipatri

unread,
Feb 4, 2014, 10:50:58 AM2/4/14
to vim...@googlegroups.com
Hi,
  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?

Thanks,
Ven

Tim Chase

unread,
Feb 4, 2014, 11:41:27 AM2/4/14
to vim...@googlegroups.com, vtadi...@gmail.com
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




Bee

unread,
Feb 4, 2014, 5:40:13 PM2/4/14
to vim...@googlegroups.com
On Tuesday, February 4, 2014 7:50:58 AM UTC-8, vtadipatri 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?

Not exactly the way you are looking for,
but it does exactly what you want:

http://bvi.sourceforge.net/

The bvi is a display-oriented editor for binary files (hex editor), based on the vi texteditor. If you are familiar with vi, just start the editor and begin to edit! A bmore program is also included in the package.

Lech Lorens

unread,
Feb 4, 2014, 6:04:29 PM2/4/14
to vim...@googlegroups.com
On Tuesday, February 4, 2014 4:50:58 PM UTC+1, vtadipatri wrote:
> Hi,
>   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?

I've written such a plugin a long time ago. I just submitted it for inclusion in Vim.

Meanwhile, find the plugin attached.

Enjoy,
Lech
xxd.vim

John Beckett

unread,
Feb 4, 2014, 7:34:19 PM2/4/14
to vim...@googlegroups.com
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.

You know about ga and g8? In normal mode, put the cursor on a
character of interest then type ga or type g8 (:help ga).
g8 is good for UTF-8 as it shows the bytes used.

John


Dominique Pellé

unread,
Feb 5, 2014, 1:44:13 AM2/5/14
to Vim List
Hi

In my ~/.vimrc, I have configured the statusline to
show the Unicode character (something like U+00E9
for é) of the character under the cursor, as well as its
UTF-8 sequence (something like 0xc3 0xa9 for é).

It looks like this (cursor on the é):

http://dominique.pelle.free.fr/pic/statusline.png

See statusline and function ShowUtf8Sequence() there:

http://dominique.pelle.free.fr/.vimrc.xhtml

Regards
Dominique

Reid Thompson

unread,
Feb 5, 2014, 8:56:47 AM2/5/14
to vim...@googlegroups.com
> 
> Regards
> Dominique
> 
> -- 

i use this in my status line.
   dec/hex\ \%03.3b/\%02.2B\ 

shows decimal and hex values for char under cursor ala with cursoron an
equals sign char
   dec/hex 061/3D


Reply all
Reply to author
Forward
0 new messages