3 ms·
I had this same problem, and I solved it thusly: (defun duplicate-line () "Duplicate the line the point is on, moving the point to the duplicate" (in
by randrews 17y ago
I had this same problem, and I solved it thusly:
(defun duplicate-line ()
"Duplicate the line the point is on, moving the point to the duplicate"
(interactive)
(save-excursion
(kill-new (buffer-substring (line-beginning-position) (line-end-position)))
(end-of-line)
(newline)
(yank)
(rotate-yank-pointer 1))
(next-line 1))
I'm sure there's a better way to do that (this is one of the first elisp things I ever wrote), but the general idea is that you duplicate the line the point is on, and then move the point down one line. It's surprisingly useful, more so than copying a line to the kill ring.