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<
This effect can be accomplished by using sub-replace-special substitution and setreg() linewise
:let @a=""
:%s//\=setreg('A', submatch(0), 'l')/g
:%d _
:pu a
:0d _
or all in one line as such:
:let @a=""|%s//\=setreg('A', submatch(0), 'l')/g|%d _|pu a|0d _
Overview: Using a substitution to append each match into register "a" linewise then replace the entire buffer with the contents of register "a"
Explanation:
let @a="" empty the "a" register that we will be appending into%s//\=setreg('A', submatch(0), 'l')/g substitute globally using the last pattern\=expr will replace the pattern with the contents of the expressionsubmatch(0) get the entire string of what just matchedsetreg('A', submatch(0), 'l') append (note: the capital "a") to @a the matched string, but linewise%d _ delete every line into the black hole register (aka @_)pu a put the contents of @a into the buffer0d _ delete the first lineConcerns:
%s//\=setreg('A', submatch(0), 'l')/g For more help
:h :s\=
:h :let-@
:h submatch()
:h setreg()
:h :d
:h :p