How do I duplicate a whole line in Emacs?

前端 未结 30 1063
时光取名叫无心
时光取名叫无心 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:47

    I don't quite remember how line duplication works anywhere else, but as a former SciTE user I liked one thing about SciTE-way: it doesn't touch the cursor position! So all the recipies above weren't good enough for me, here's my hippie-version:

    (defun duplicate-line ()
        "Clone line at cursor, leaving the latter intact."
        (interactive)
        (save-excursion
            (let ((kill-read-only-ok t) deactivate-mark)
                (toggle-read-only 1)
                (kill-whole-line)
                (toggle-read-only 0)
                (yank))))
    

    Note that nothing gets actually killed in process, leaving marks and current selection intact.

    BTW, why you guys so fond of jerking cursor around when there's this nice'n'clean kill-whole-line thingy (C-S-backspace)?

提交回复
热议问题