Let’s say I have several lines like:
$repeat_on = $_REQUEST['repeat_on'];
$opt_days = $_REQUEST['opt_day'];
$opt_days = explode(",", $opt_days);
… and so on.
Let’s say I use visual mode to select all the lines: how can I replace everything from = to the end of the line so it looks like:
$repeat_on = NULL;
$opt_days = NULL;
$opt_days = NULL;
With the block selected, use this substitute:
The substitution regex changes each line by replacing anything between
=and the end of the line, including the=, with= NULL;.The first part of the command is the regex matching what is to be replaced:
=.*$.=is taken literally..means any character..*means: 0 or more of any character.$for end of line, but this actually isn’t necessary here: try it also without the$.So the regex will match the region after the first
=in each line, and replace that region with the replacement, which is= NULL;. We need to include the=in the replacement to add it back, since it’s part of the match to be replaced.When you have a block selected, and you hit
:to enter a command, the command line will be automatically prefixed with a range for the visual selection that looks like this:Continue typing the command above, and your command-line will be:
Which will apply the replacement to the selected visual block.
If you’ll need to have multiple replacements on a single line, you’ll need to add the
gflag: