I am dealing with a block of comments like:
//this is comment 1
//this is comment 2
//this is comment 3
//this is comment 4
I would like to make it look like:
//this is comment 1
//this is comment 2
//this is comment 3
//this is comment 4
Is there a Vim shortcut to make this transformation on selected lines while staying in command mode?
You can use the
:substitutecommand. With the cursor anywhere on thefirst of the lines:
This inserts an additional newline at the end of each line.
You can also use the
:globalcommand. With the cursor anywhere onthe first of the lines, run:
For each of the next four lines, this executes the
oNormal-modecommand, adding a new blank line.
In both of the commands, the
,+3prefix is a range for thecommand, see
:help range. Briefly, the comma separates the addressesof the starting and ending lines of the range, where the current line
is used if we omit the former of the two addresses. The
+3addressrefers to the line that is three lines below from the current line.
Rather than specifying a range, e.g.,
,+3, for either of thesecommands, you can use the
VNormal-mode command to make a Visualblock across all the lines that you want. Then typing
:to begin thecommand will auto-fill the range specifying the visual block, and you
can then enter either of the two commands starting with
sorg: