Sometimes I find it useful to switch to hex mode when editing a file in vi. The command for switching is not very obvious so thought I’d share…
So, open a file in vi as usual, hit escape and type:
:%!xxd to switch into hex mode
And when your done hit escape again and type:
:%!xxd -r to exit from hex mode.
Okay, so this isn’t actaully switching to vi’s ‘hex mode’; vi doesn’t have one. What the above actually does is to stream vi’s buffer through the external program ‘xxd’.
Dan Douglas says:
February 16, 2011 at 10:41 pm
This isn’t a “hex mode”. :! is Vim’s filter syntax. :%!xxd selects the range of the entire buffer, filters it through the external xxd program and replaces each line with the resulting output (though xxd appears to be part of the vim package on my distro, not a standard Linux command). You could accomplish the same by launching Vim with a bash command like “vim <(xxd filename)" assuming xxd is located in your $PATH. It should be nicely highlighted nicely if ft=xxd.