How do I duplicate a whole line in Emacs?

前端 未结 30 1085
时光取名叫无心
时光取名叫无心 2020-12-04 05:20

I saw this same question for VIM and it has been something that I myself wanted to know how to do for Emacs. In ReSharper I use CTRL-D for this action. What is the least num

30条回答
  •  再見小時候
    2020-12-04 05:24

    As mentioned in other answers, binding key strokes to lisp code is a better idea than binding them to another key strokes. With @mw's answer, code duplicates the line and moves the mark to end of new line. This modification keeps the mark position at same column on the new line:

    fun duplicate-line ()
      (interactive)
      (let ((col (current-column)))
        (move-beginning-of-line 1)
        (kill-line)
        (yank)
        (newline)
        (yank)
        (move-to-column col)))
    

提交回复
热议问题