It happens more often than not that I have to comment several lines at once in Vim. Methods that I know are not as fast as say TextMate way to comment lines out.
What is your favorite way to do it?
I currently use:
#
for Ruby):
which gives you a :'<,'>
prompt which you can extend to :'<,'>s/^/#/
mm
:'m,.s/^/#/
I like method 1 the most but I still hope there is a better way.
To comment out a single line in Vim, enter Visual Mode by pressing Ctrl + V . Next, navigate to the line you wish to comment out and press the C key. Depending on your Vim configuration, this should comment out the selected line. That's all there is to it – easy, isn't it?
You start your editor, navigate down to the beginning row of the block you want to comment out. You hit i to go into insert mode, enter // to comment, hit ESC to go back to command mode, hit j to navigate down to the next row, and then repeat until all the rows are commented out.
The vimrc or Vim configuration file uses the double quote for a single-line comment. A single quote at the start of the line will make this line a comment and not be interpreted as a configuration.
I think you described the most popular ways to comment code, but if you are open to use Vim Scripts, give a look to those:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With