If you want to bind it to a key you could record that as a macro for e.g., but I find that sequence is simple enough that I don't think hard about it
The first C-k only kills to end-of-line, to capture the line ending (\n) you need another C-k. The first C-y only puts back what you killed, so that needs to be doubled also to actually change the buffer in the desired way.
Subsequent C-y commands will add more copies of the line, but I find that 99% of the time it's only a single duplicate of a line that I want.
C-S-Backspace C-yy does the same thing, btw.
I really like writing Lisp so Emacs has a simple way of doing anything I want, but it’s not for everyone.
Generally, the Spacemacs defaults work really well for me, and for many others. Elisp hacking was more relevant in the past. These days, with Spacemacs and other similar community efforts that deliver sane and well thought out settings, not much tinkering is required.
And if it's a situation where you really need to make the user define a keyboard shortcut, don't make them do C-c followed by the actual shortcut, let them define single keystroke shortcuts to do what they want. Multiple keystroke shortcuts are so damn annoying.
https://www.emacswiki.org/emacs/CopyingWholeLines#toc3
and then just eval it to get new functionality? And the various implementations I linked to here are trivial to figure out and write yourself with even the most passing familiarity with Emacs Lisp. Even if you're a complete newcomer to the language, Emacs is self-documenting and can teach you everything from inside the editor.
That's simple by Emacs standards. :-)
If you need it simpler, write and save a keyboard macro.
Or when debugging, I don't want to change the old code, so I copy the line, comment it out, and work with the duplicated line.
You've never had to do that?
The Emacs way of solving a workflow problem is instructing Emacs how to solve it for you. For instance, you mention:
1. Copy the line the cursor (point) is on;
2. Insert the copied line below/above point;
3. Commenting out the line you copied;
By the sound of things you do 1 and 2 with a command in Vim and the 3rd option with another command. In Emacs, I would simply program a function to do all 3 and bind it to a key.
"Writing a function for the full change" is simply not a tenable thing to do. "Duplicate a line" is fundamental in the same way that "go to start of line" or "indent this line one more tabstop" is.
As someone who has spent years using both Emacs in "Emacs mode", and vim/evil-mode, there's no question to me that the modal vim-style editing is superior to Emacs's. That's not to say that "Emacs mode" is bad: it's far superior to most editing styles. Just not evil/vim :)
Don't get me wrong: I adore Emacs, and I use it for hours and hours every day. But if it weren't for evil-mode, I would go back to Vim in a heartbeat.
So write a function for "duplicate line" and use it from now on. It's very easy to do. Just as it's easy to write function for a full edit.
A general algorithm to get one started:
1) Execute the edit you want to reuse.
2) Press C-h l, or M-x view-lossage, to see all the keypresses you made recently, along with elisp commands they executed.
3) You now know all the operations you did. Most of the time, you can recreate the edit by just wrapping them in parens, and then wrapping the whole block with (progn).
4) You're now ready to turn it into a function. Read up on 'defun and 'interactive forms. For best results, check out the documentation for each command you used during edit, via C-h f - some commands are meant for direct usage, and have a (faster, better) variant meant for use from within code; this is usually documented.
5) Tweak your function to make it more general along the dimensions you need, bind it to a key, and now you've just implemented what elsewhere would take a large plugin.
Also, it reads straight from command-history variable (another thing I didn't know about). You can preview and browse it via C-h v command-history. Or, write your own elisp operating on it (perhaps interactively, by IELM - the elisp REPL).
I say that as a Vim user that duplicates lines constantly. Vim definitely changes your coding patterns; for better or worse because it can be soo frictionless.
And even with vanilla emacs it's probably a one liner in your config to get vi bindings.
Once you create a macro like that you can run it, name it, save it to your config, bind it to a key, whatever suits your workflow.
I never really thought of how much I do this manually, so I just set it up for myself right now. I'll probably rewrite it as an elisp function though.
Or ctrl a ctrl k ctrl k ctrl y (move) ctrl y.
Is it really something that’s so common that it needs a command?
The more I use Git the more I've been committing/diffing for similar effect; but it's still much more overhead for smaller checks.
If you've got a vim setup that works for you, great.