I often find myself repeatedly yanking something after doing some kills and it becomes a process like:
Each time I kill some text it pushes the first kill back in the kill ring so that I need to cycle through all the kills to return to text I want to yank. What I want to do is repeatedly yank the same text while killing text in-between yanks. Is this possible?
If you want to yank the region you killed before the last one, hit Ctrl-y to yank, and then Meta-y to yank the previous kill instead of the one you just retrieved.
Killing by Lines The simplest kill command is C-k . If given at the beginning of a line, it kills all the text on the line, leaving it blank. When used on a blank line, it kills the whole line including its newline. To kill an entire non-blank line, go to the beginning and type C-k twice.
To kill an entire non-blank line, go to the beginning and type C-k twice. More generally, C-k kills from point up to the end of the line, unless it is at the end of a line. In that case it kills the newline following point, thus merging the next line into the current one.
The kill ring is a list of blocks of text that were previously killed. There is only one kill ring, shared by all buffers, so you can kill text in one buffer and yank it in another buffer. This is the usual way to move text from one buffer to another.
Don't use the kill ring; put the text into a register instead. C-x r s a
to store the region's text into (say) register "a"; then C-x r i a
to insert it elsewhere.
This is a strange hack, but may help.
The first time you use M-y
you normally get an error (no previous yank). So the idea is that this first time you get the last yank instead of the last kill.
For storing that last yank I use the 'Y' register in this example.
These 2 functions would wrap around yank and yank-pop. You expect bugs, I expect suggestions.
(defun jp/yank (&optional arg) "Yank and save text to register Y" (interactive) (set-register ?Y (current-kill 0 t)) (yank arg)) (defun jp/yank-pop (&optional arg) "If yank-pop fails, then insert register Y" (interactive) (condition-case nil (yank-pop arg) (error (insert (get-register ?Y))))) (global-set-key (kbd "M-y") (quote jp/yank-pop)) (global-set-key (kbd "C-y") (quote jp/yank))
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