Emacs: how to delete text without kill ring?

I'd like to just delete some text so I can yank some other text instead of it. How can I do that? C-w cuts the selected text to kill ring and I end up without the text I wanted to yank.

Also, is it possible to yank text directly instead of some text without even pressing buttons to kill it?


Solution 1:

I type M-x delete-region quite often, but you can bind it it to a key.

With Delete Selection Mode in newer versions of Emacs you don't have to type a command just start typing:

By default, text insertion occurs normally even if the mark is active—for example, typing a inserts the character ‘a’, then deactivates the mark. Delete Selection mode, a minor mode, modifies this behavior: if you enable that mode, then inserting text while the mark is active causes the text in the region to be deleted first. Also, commands that normally delete just one character, such as C-d or DEL, will delete the entire region instead. To toggle Delete Selection mode on or off, type M-x delete-selection-mode.

Solution 2:

You can use M-y after C-y to insert previous item from the kill ring, or use browse-kill-ring package.

As for the second question, see DeleteSelectionMode.