There has no rmap, replace mode map is created in imap with a mode test:
inoremap <expr> <a-k> mode() ==# 'R' ? 'replace' : 'insert'
:h mode() is transient, you must test it in :h map-expr.
Note it won't work for r.
Here's a simple macro-based solution.
First place your cursor at the beginning of bunch: 0W.
This records a recursive macro into the "q register that will remove everything from the current position to the end of the line, apart from the URLs.
Then undo the changes you made while recording the macro: 3u
Here's a quick and dirty solution. You can certainly find/create input HTML that will break this, but it works fine for simple input such as your example:
Add a " at the end of the commas:
This is simply using a :normal command to execute the equivalent of typing 0Ea" in normal mode.
Split the line on the URLs:
Here we use ...
Use this substitution command:
%s/\(\d*,,,\).*href="\(https:.*\)" .*/\1 \2 /
% means "all lines in the buffer"
\d*,,, is any number of digits followed by 3 ","
.*href=" is anything following up to https:
" .* is all the text from closing quote to the end of the line including the quote (note the space between quote and dot.
Use the :normal command with a sequence of steps
This is similar to the answer using a macro, but instead of recording the steps, we'll pass them to the :normal command and use a range to execute the sequence on every line.
We can use the following command:
The .,.+3 part is a range and it means from this line until 3 lines ...
Record and replay a macro
You can record a macro to handle each line, and then replay it to handle the following lines using the same sequence of commands.
Let's make a somewhat more interesting example, with varying lengths of variable names, with unaligned =s, but fixed single space around the =s. Let's also add some indentation to the lines:
v1 = ...
Use blockwise Visual mode on aligned columns of text
If the = signs are aligned, you can use blockwise Visual mode to execute this replacement.
Let's make a somewhat more interesting example, with varying lengths of variable names, but still aligned =s. Let's also add some indentation to the lines:
v1 = a1
v2 = a2
v345 = a345
Use a :substitute command with a regex
Using a :substitute command is pretty Vimish! This method will be good for you if you feel comfortable with Vim regexes, or if your input is uniform enough that you can use a simple regex to match it.
A simple way would be to use Visual mode to select a range of lines where to apply the transformation, then use the ...
The following is taking place in the substitute command
Search for 1 or 0, remember it as submatch 1 (between the first / and second /)
Replace with the value by subtracting from 1 (between the second / and third /)
1 becomes 0 and 0 becomes 1
\= is interpreted as the beginning of a mathematical expression in the substituted ...
I'm actually surprised there is no native tr in vi/vim, but if your platform is UNIXy enough, there's an external command for just this:
:%!tr 01 10
This is what I would personally use, but it may not be portable enough for you.
Similar to @LucHermitte's answer, the SwapStrings plugin lets you do
:%SwapStrings 0 1
My own PatternsOnText plugin provides (among many others) a :SubstituteMultiple command that can do swaps as a corner case of doing multiple substitutions atomically (that is, without introducing a temp replacement):
:%SubstituteMultiple /0/1/ /1/0/ g
I'm quite certain I've already gave an answer to the general case either here on vi.SE, or on stackoverflow, but impossible to find the Q/A...
In that answer I provide the command CycleSubstitute that could be used in your case in the following way
I've packaged it here. And it's implemented in the following way:
There's a bunch of excellent answers here already, but for the sake of completeness I feel like I should point out that, in most practical respects, if you concatenate multiple ex commands with the bar character |, they act like a single operation.
In particular, they will lead to a single item in each of the undo tree and changelist.
As such, the ...