Copy/Paste seems broken for hexl-mode, eg. M-w copies the hex tables to the clipboard, rather useless. Since hexl-mode has overwrite-mode by default, how can the following be implemented?

  • M-w should copy marked binary data to the clipboard
  • C-y should insert contents of clipboard by overwriting, starting at cursor position
  • C-w should overwrite the marked area with hexl-mode-clear-value
  • DEL should set current byte to hexl-mode-clear-value and go to previous byte

hexl-mode-clear-value should be a customisable variable defaulting to \x00.

If Emacs is not in overwrite mode, copy/paste should work like plain text files, though this seems like low priority / undesirable since skewing binary data equals data corruption in most cases.

1 Answer 1


I implemented such a variant of overwrite-mode as part of nhexl-mode-0.4 (available from GNU ELPA), which I called nhexl-overwrite-only-mode. It also works in "normal" editing modes (i.e. outside of nhexl-mode) but it won't work for hexl-mode, I'm afraid.

  • Literally immediately installed nhexl-mode solely for the overwriting yank! Great work, and huge thank you. Wild to me that this isn't anything available in Emacs out-of-the-box to do this (especially since overwrite-mode exists, it's such a small step from that to realizing that it would be useful to have the ability to apply the same behavior change to inserts done from Lisp). You may want to consider turning nhexl-overwrite--yank-wrapper in a public API: here's one example use-case).
    – mtraceur
    Commented May 18, 2023 at 7:39
  • For what it's worth, I'm implementing my own alternative which handles block yanking and vi-style line pasting (in a way that builds on Evil and reuses some of the code I already inject into Evil to fix up the paste behavior into something I consider more sensible), so I'll be totally fine if you don't promote your yank wrapper to a public API, but I do think this is a good example of how this kind of thing might be really useful to other people as a building block.
    – mtraceur
    Commented May 18, 2023 at 7:44
  • I should move that overwrite-only thingy out of nhexl-mode, indeed. [ BTW, Emacs really needs someone (or a group of people) to sit down and figure out how to better integrate Evil and "normal" Emacs, because the two communities are forking. ]
    – Stefan
    Commented May 19, 2023 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.