How to comment multiple lines at once?
How can I select a bunch of text and comment it all out?
Currently I go to the first line, go to insert mode then type
#left-arrowdown-arrow and then I repeat that sequence, perhaps saving a few keystrokes by using the
.repeat feature to do each line.
Is there anyway I could (for instance) select either multiple lines in visual mode or by using a range of lines and an ex ('colon') command and for that range comment out all the lines with a
#to make them a "block comment".
The ability to quickly 'de-comment' (remove the
#'s) for a block comment would also be nice.
You can do it with the following commands:
Obviously, here we're commenting lines from 66 to 70 (inclusive).
Maybe on your vim version but I'm sure of it, "s" stands from "substitution" /^ begining of the line by /# (hash). No mistery here.
if you want to comment `//` instead of `#` need to escape them with \. `:66,70s/^/\/\/`