Reputation: 22984
First of all, this is not a dup of
cua-mode
.I'm talking about the Emacs Delete Selection Mode, I used to be able to delete selection of text by just pressing Delete key. I found my proof here.
In order to set emacs to delete the selected text when you press DEL, Ctrl-d, or Backspace, add the following to your .emacs file:
(delete-selection-mode t)
However, now, with my Emacs 24, the Delete key doesn't work on the selection anymore (only Backspace does). This is really annoying because for all editors that I use, pressing the Delete key will delete the text selection. I don't understand why Emacs has to be so different and inconvenient. Anyway,
Any easy way to fix it? I don't know whether the comment of the following was a joke or the actual solution:
(setq behave-like-something-actually-usable-by-humans t)
Thanks
PS, my Emacs 24 is from nightly build:
$ emacs --version | head -1
GNU Emacs 24.3.50.1
EDIT: The answer from Drew, if it is unclear to you (I got that on third attempt),
(global-set-key (kbd "<delete>") '(lambda (n) (interactive "p") (if (use-region-p) (delete-region (region-beginning) (region-end)) (delete-char n))))
works for me.
Upvotes: 2
Views: 1664
Reputation: 9
In 21.4.22, I had to use the (region-active-p)
function instead of (use-region-p)
(global-set-key `backspace '(lambda (n) (interactive "p") (if (region-active-p) (delete-region (region-beginning) (region-end)) (delete-backward-char n))))
Upvotes: 0
Reputation: 69
There appears to have been a change to the behavior of delete-char
. I experienced that as well as I had bound DEL to that command. I had success binding the key to delete-forward-char
instead, which implements the old behavior. See here.
Upvotes: 0
Reputation: 30701
The <delete>
key is bound by default to kill-line
. It sounds like you want to bind it instead to delete-region
. Just do it.
(global-set-key (kbd "<delete>") 'delete-region)
Upvotes: 2