Implementing comment-line26 Jan 2015, by Artur Malabarba.
Why we don't have a
comment/uncomment-line function is beyond me. While we fix
that, might as well make it as complete as possible.
Short and sweet, isn't it? In analogy to M-;. I find C-; to be a great binding for it. This way I can quickly comment 3 lines by hitting C-3 C-;.
Also, because it moves forward after commenting, you can conveniently do things like comment every other line by repeatedly doing C-; C-n.
The previous version didn't quite work for negative prefix arguments, so I've updated the above snippet to fix that.
Also, quite a few people requested (or proposed) a version which acts on region if active. I already use M-; for that (and I also its other modes of operation), but I can see why people would want that so I've added it below. It's similar to the one suggested by Kaushal Modi.