How to avoid accidental killing of text in emacs?

I have a selection mode (forget what he called) that shows me, highlighting the text, which region I selected between the label and the point. it is very convenient when killing regions. However, sometimes even when the text is not displayed explicitly, but I accidentally press Cw, it still sometimes kills some text. My question is, how can I stop this behavior? I just want him to kill the text IF I selected it.

+4
source share
4 answers

Define your own function and replace the key binding:

(defun my-kill-region () (interactive) (if (region-active-p) (call-interactively 'kill-region) (message "Region not active, didn't kill"))) (global-set-key (kbd "Cw") 'my-kill-region) 
+8
source
 Mx transient-mark-mode 

will keep the selected area even after you start typing, and when you use C-Space to set the label. Then you will see that Cw will kill.

+6
source

Set the mark-even-if-inactive variable to nil . That way you can only kill the text if it is really selected.

+6
source

Press C-Space (the set-mark-command command) immediately before Cw to place a mark at the cursor position so that the text between the mark and the cursor position is not killed.

+1
source

All Articles