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?
Emacs provides many ways to delete text. The simplest way to delete text is to press the DEL key, which deletes the character immediately to the left of the cursor. See Figure 2-3 for possible locations of the DEL key on your keyboard. DEL is easiest to define by what it does: it deletes the previous character.
Delete Selection mode lets you treat an Emacs region much like a typical text selection outside of Emacs: You can replace the active region just by typing text, and you can delete the selected text just by hitting the Backspace key ( 'DEL' ).
# Press z as many times as you wish.
kill means removing text and putting it in the kill ring. delete means removing text and not putting it in the kill ring.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With