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?
How to duplicate a whole line in Emacs
commandeditingeditoremacstext;
Related Topic
- How to move to end of line in Vim
- Using Emacs to recursively find and replace in text files not already open
- Differences between Emacs and Vim
- Git – How to make Git use the editor of the choice for commits
- Multiple commands on same line
- Linux – How to find all files containing specific text on Linux
- C++ – Redirect std::cout to newly created console
Best Answer
I use
which breaks down to
C-a
: move cursor to start of lineC-SPACE
: begin a selection ("set mark")C-n
: move cursor to next lineM-w
: copy regionC-y
: paste ("yank")The aforementioned
amounts to the same thing (TMTOWTDI)
C-a
: move cursor to start of lineC-k
: cut ("kill") the lineC-k
: cut the newlineC-y
: paste ("yank") (we're back at square one)C-y
: paste again (now we've got two copies of the line)These are both embarrassingly verbose compared to
C-d
in your editor, but in Emacs there's always a customization.C-d
is bound todelete-char
by default, so how aboutC-c C-d
? Just add the following to your.emacs
:(@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.