I would like to insert a hash at the beginning of the selected block of text in VIM (ruby comment). I selected rows in Visual Mode, but how do I perform the same operation on all rows?
You have two main options:
Select in block visualization mode (ctrl-v), then use I to insert the same on the left side of the entire block. Similarly, A adds; see block statements .
I
A
Select the lines in normal visual (v) or visual line (V) mode, then run the same command for all of them, for example s/^/# / or normal I# . Input : while you have a visual selection, the visual selection is automatically used as a range of lines (indicated by the symbol '<,'> ).
s/^/# /
normal I#
:
'<,'>
In visual mode, run
:'<,'>s/^/#
In fact, '<,'> will be inserted automatically when you press :
You better use this.
COMMAND MODE with a given number to see the lines
: 10.50s / ^ / # / g
The first number before the decimal is the start line and the second number after the decimal is the final line. Both are included.