Delete data from the middle of a binary file with hexl-mode
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.
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.