When wanting to replace a region of text with another, I usually mark them with C-SPC (set-mark-command), press some arrow/movement keys, then type the text that I want. To illustrate:

I like biscuits.

Say I want to replace like with love and my cursor is at the letter l. I press C-SP M-f, then type love.

Usually this works with no problem. But sometimes, after I accidentally press some combination of keys, a setting changes and when I type l, the selected like is not replaced.

My question is, which setting is this?


What happens when like is not replaced? Is the letter you typed inserted at the cursor (which is then after the e in like)?

A guess is that you've somehow toggled Delete-Selection mode: turned it off instead of on.

When the mode is on and the region is active (i.e., text is selected/highlighted), text you type replaces the selected text. When off, text you type is inserted at the cursor.

Do you see the same thing when you start Emacs with emacs -Q (no init file)? By default, Delete-Selection mode is off. Probably something in your init file is probably turning Delete-Selection mode on, and then you are likely doing something that turns it off.

Maybe the command that toggles the mode on/off, which is delete-selection-mode, is bound to some key that you sometimes hit accidentally. To find out, use C-h w (command where-is), and type delete-selection-mode at the prompt. It will tell you which key, if any, that command is bound to.

If this doesn't help, you may need to provide more info about what you use in your init file. Try to provide a step-by-step recipe, starting from emacs -Q, to reproduce the problem.

For more info about delete-selection-mode: C-h f delete-selection-mode.

  • Yes, that's it. In my init file, I turn delete-selection-mode on. But I wonder how it is turned off accidentally. where-is tells me that the delete-selection-mode is not bound to any key. – Budiman Snowman Oct 2 '20 at 8:01
  • In that case, perhaps it gets turned off by some mode you turn on or some library you load. If you can reproduce the problem then bisect your init file to find the culprit. – Drew Oct 2 '20 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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