emacs: kill and yank
Killing and Yanking Text
Key Binding | Purpose |
---|---|
C-d | Delete character |
<backspace> |
Delete previous character |
M-d, C-<backspace> |
Kill word |
C-k | Kill rest of line |
M-k | Kill sentence |
C-M-k | Kill s-expression |
C-S-<backspace> |
Kill current line |
Some clipboard-emuivalent commands:
Key Binding | Kill Ring Purpose | Clipboard |
---|---|---|
C-w | Kill active region | cut |
M-w | Copy to kill ring | copy |
C-M-w | Append kill | |
C-y | Yank last kill | paste |
M-y | Cycle through kill ring, replacing yanked text | - |
Emacs’s kill commands are best summarized with five simple rules:
Consecutive kills append to the kill ring. When you kill some words use M-d, and then move to next line and kill another three words. Your last three words are what you yank from the kill ring, not all six! The movement command broken the cycle.
The kill ring can hold many items and like the undo ring you cannot lose information in the kill ring.
The kill ring is global and between all the buffers in Emacs. You can view the kill ring - by running C-h v kill-ring.
Killing is also deleting when you don't care about the killed text.
Marking is unnecessary for most operations that involve syntactic units. There are two exceptions:
- If you want to copy(M-w) the region, it's quicker to mark first and then copy.
- If you want to kill or copy odd-shaped regions that don't conform to multiples of synthetic units.
Appending to the kill ring
Type C-M-w, If next command is a kill command, it will append to the last element in the kill ring.
You can use the method to collect several comments into one big group.
Yanking Text
Key Binding | Purpose | Clipboard |
---|---|---|
C-y | Yank last kill | paste |
M-y | Cycle through kill ring, replacing yanked text | - |
Cycle through the kill ring is easy:
- Press C-y where you want the yanked text to appear.
- Without executing another command - type M-y to step back through Emacs' kill ring.