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:
Method 1:
- go to first char of a line and use blockwise visual mode (ctrl-v)
- go down/up until the first characters of every lines you want to comment out are selected
- use shift-i and then type your comment character (
#
for Ruby) - use esc to insert the comment character to every line
Method 2:
- select lines you need to comment out using linewise visual mode (shift-v)
- type
:
which gives you a:'<,'>
prompt which you can extend to:'<,'>s/^/#/
Method 3:
- go to the first line to be commented out
- make a bookmark for example typing
mm
- go to the last line to be commented out
- type
:'m,.s/^/#/
I like method 1 the most but I still hope there is a better way.