emacstexteditoreditingcommand

How do I duplicate a whole line in Emacs?


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 number of commands to perform this in Emacs?


Solution

  • I use

    C-a C-SPACE C-n M-w C-y
    

    which breaks down to

    The aforementioned

    C-a C-k C-k C-y C-y
    

    amounts to the same thing (TMTOWTDI)

    These are both embarrassingly verbose compared to C-d in your editor, but in Emacs there's always a customization. C-d is bound to delete-char by default, so how about C-c C-d? Just add the following to your .emacs:

    (global-set-key "\C-c\C-d" "\C-a\C- \C-n\M-w\C-y")
    

    (@Nathan's elisp version is probably preferable, because it won't break if any of the key bindings are changed.)

    Beware: some Emacs modes may reclaim C-c C-d to do something else.