Duplicate line under cursor

A function to duplicate whatever the line under the cursor is. If you are a programmer this is something that you probably do a lot. However C-a C-k C-y C-y or C-a M-spc C-e M-w gets old very fast. Instead, put the following function in your .emacs:


(defun duplicate()
    "Duplicate it the line we are on"
	(interactive)
    (let (
        (beg (line-beginning-position))
		(end (line-end-position)))
	(copy-region-as-kill beg end)
	(beginning-of-line)
	(forward-line 1)
	(yank)
	(newline)
	(forward-line -1)))

and bind it to any key-kombo you like (I used C-c C-j), and duplicating lines is suddenly just a key press away.

Last modified: 22.09.2009
Table of content