3 ms·
"With Vim I had defined a keybinding that selected the last pasted text. It was useful when you wanted to reformat or indent text that you've pasted from somewh
by unhammer 12y ago
"With Vim I had defined a keybinding that selected the last pasted text. It was useful when you wanted to reformat or indent text that you've pasted from somewhere. At the moment I've been unable to reproduce this in Emacs."
- in non-evil-mode at least, C-x C-x will reselect what you last pasted if you haven't moved. What really happens is that when you paste, the "mark" is set there (equivalent to doing C-SPC), and C-x C-x will switch point (your cursor) and the mark.
However, if you want a function that works even after you've moved around a bit you could do e.g.
(defadvice yank (around advice-yank-set-vars activate)
(setq yank-last-start (point))
ad-do-it
(setq yank-last-end (point)))
(global-set-key (kbd "C-c C-y")
(defun select-last-yank ()
(interactive)
(push-mark yank-last-start)
(goto-char yank-last-end)
(activate-mark)))
although this'll fail if you've inserted text before the yanked text (I suppose you could do it more correctly by setting text-properties, but that's getting rather advanced)
- klibertp 12y agoNo need for text properties, just make "yank-last-start" and "yank-last-end" markers instead of simple ints (https://www.gnu.org/software/emacs/manual/html_node/elisp/Markers.html https://www.gnu.org/software/emacs/manual/html_node/elisp/Ma...) - they will be moved automatically with every edit.
- unhammer 12y agoOh, nice, I suspected there was a better way :-)