Skip to content

Instantly share code, notes, and snippets.

@rejeep
Created June 13, 2012 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rejeep/2922929 to your computer and use it in GitHub Desktop.
Save rejeep/2922929 to your computer and use it in GitHub Desktop.
Comment and duplicate line
(defun comment-and-duplicate-line ()
"Copy current line to line below and comment current line."
(interactive)
(let* ((beg (line-beginning-position))
(end (line-end-position))
(line (buffer-substring-no-properties beg end))
(column (current-column)))
(comment-region beg end)
(goto-char (line-end-position))
(newline)
(insert line)
(move-to-column column)))
(global-set-key (kbd "C-c C-d") 'comment-and-duplicate-line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment