Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a fairly large binary file (a few tens of MB) and would like to remove a few KB somewhere in the middle, it's sandwiched data not the beginning nor the end.

Ideally I'd like to use emacs and hexl-mode seems a likely candidate.

Is it possible to delete one line from hexl buffer? Ctrl-k does not seem to do the job. I'm happy to look at the code but for whatever reason looking for hexl-mode.el all I find is the compiled .elc file on my Ubuntu 10.04 machine Emacs 23.1.

Additionally: in a sneaky move I'd like to add another hexl-mode question that is not directly related to the question as phrased in the title but is part of the complete problem I'm facing: It would be very useful for me if I could display X hexadecimal characters per line where X obviously changes with the format of the binary file I'm editing, I could not find a way to do that with hexl-mode and thought I'll throw the question here.

share|improve this question

Hexl mode does not allow you to delete characters. This answer from stack overflow suggests a workaround: overwrite the characters you want to delete with another character (say "X"), switch out of hexl mode, find the characters and delete them there.

share|improve this answer

Use nhexl-mode (which can be installed as a package from ELPA). Nhexl-mode is a minor mode; the text remains editable in the major mode the buffer was already in.

By default, nhexl-mode activates overwrite mode, but you can still delete. To insert text, turn off overwrite mode with M-x binary-overwrite-mode.

You can put the following code snippet in your init file (~/.emacs) to bind the Insert key to toggling overwrite mode in nhexl-mode.

(unless (boundp 'nhexl-mode-map)
  (defvar nhexl-mode-map (make-sparse-keymap)
    "Keymap used when `nhexl-mode' is active."))
(define-key nhexl-mode-map [insert] 'binary-overwrite-mode)

This may also be of interest if you use nhexl-mode.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .