Question

I use vim regularily for all my needs. On very rare occasions I need to open binary files via a hex editor look, and for that I start vim on the file and then run it through xxd via the command: %!xxd

My question is, how can I have my command line open a file directly in this manner, if the option exists? something like typing: gvimbin <file> and then it opens in the right manner.

Edit: to be clear, I am looking for a complete solution that allows running vim exec commands on startup.

Was it helpful?

Solution

You can execute commands after Vim startup by passing them via -c:

$ gvim -c '%!xxd' file.bin

This can even be simplified so that when Vim is started in binary mode (-b argument), it'll automatically convert the file. Put the following into your ~/.vimrc:

if &binary
    %!xxd
endif

and start with:

$ gvim -b file.bin

Also have a look at the hexman.vim - Simpler Hex viewing and editing plugin; it makes it easier to deal with hexdumps.

OTHER TIPS

Like Felix say:

xxd <file> | vim -

You can put this into script for example vimxxd:

#!/bin/sh
xxd $1 | vim -

and use like: vimxxd file.txt

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top