My specific case is a text document that contains lots of text and IPv4 addresses. I want to remove everything except for the IP addresses.
I can use :vglobal<
:set nowrapscan
:let @a=""
gg0qac/\v(\d{1,3}\.){3}\d{1,3}//e+1@aq@adG
Explanation:
set nowrapscan disables ability to seek «past the end of file».let @a="": empty the a register.gg0: go to the first column (0) of the first line (gg).qa: start writing macros.c/{pattern}: change until pattern.c{motion}: replace text with newline (here {motion} is /{pat}).//e+1: search for last pattern, go one character left past its end (wraps around a newline, but if your lines looks like this: IPIP , there may be problems).@a: execute @a macros (it is empty when you are recording it, but when you are finished it will repeat steps 1-7 until it gets an error).q: end recording @a.@a: execute @a macros.dG: delete to the end of file.