Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: how to delete text without kill ring?

Tags:

emacs

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?

like image 473
mannicken Avatar asked Mar 12 '09 04:03

mannicken


People also ask

How do you delete text in Emacs?

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.

How do I delete selected text in Emacs?

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' ).

How do I delete an entire line in Emacs?

# Press z as many times as you wish.

What is difference between kill and delete command?

kill means removing text and putting it in the kill ring. delete means removing text and not putting it in the kill ring.


2 Answers

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.

like image 197
ashawley Avatar answered Oct 11 '22 10:10

ashawley


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.

like image 31
Eugene Morozov Avatar answered Oct 11 '22 10:10

Eugene Morozov