Search code examples
regexvimfile-manipulation

Saving results of Regex Search into a file with Vim


I've got a HTML file, and I'd like to grab all the links that are in the file and save it into another file using Vim.

I know that the regex would be something like:

:g/href="\v([a-z_/]+)"/

but I don't know where to go from here.


Solution

  • Put your cursor in the first row/column and try this:

    :redir > output.txt|while search('href="', "We")|exe 'normal yi"'|echo @"|endwhile|redir END