Search code examples
emacs

How to replace a region in emacs with yank buffer contents?


When I use VIM or most modeless editors (Eclipse, NetBeans etc.) I frequently do the following. If I have similar text blocks and I need to change them all, I will change one, copy it (or use non-deleting yank), select next block I need and paste the changed version over it. If I do the same thing in emacs (select region and paste with C-y), it doesn't replace the region, it just pastes at the cursor position. What is the way to do this in emacs?


Solution

  • Add this to your .emacs:

    (delete-selection-mode 1)
    

    Anything that writes to the buffer while the region is active will overwrite it, including paste, but also simply typing something or hitting backspace