Задача здесь заключается в извлечении всех ссылок, где может быть несколько он-лайн, в противном случае вы можете просто сделать:
" Extract all lines with href=
:g/href="[^"]\+"/w >> list_of_links.txt
" Open the new file
:e list_of_links.txt
" Extract the bit inside the quotation marks
:%s/.*href="\([^"]\+\)".*/\1/
Самым простым подходом, вероятно, было бы сделать это:
" Save as a new file name
:saveas list_of_links.txt
" Get rid of any lines without href=
:g!/href="\([^"]\+\)"/d
" Break up the lines wherever there is a 'href='
:%s/href=/\rhref=/g
" Tidy up by removing everything but the bit we want
:%s/^.*href="\([^"]\+\)".*$/\1/
В качестве альтернативы (по аналогичной теме),
:g/href="[^"]\+"/w >> list_of_links.txt
:e list_of_links.txt
:%s/href=/\rhref=/g
:%s/^.*href="\([^"]\+\)".&$/\1/
(см .: help saveas,: help: vglobal,: help: s)
Однако, если вы действительно хотите сделать это более прямым способом, вы можете сделать что-то вроде этого:
" Initialise register 'h'
:let @h = ""
" For each line containing href=..., get the line, and carry out a global search
" and replace that extracts just the URLs and a double quote (as a delimiter)
:g/href="[^"]\+"/let @h .= substitute(getline('.'), '.\{-}href="\([^"]\+\)".\{-}\ze\(href=\|$\)', '\1"', 'g')
" Create a new file
:new
" Paste the contents of register h (entered in normal mode)
"hp
" Replace all double quotes with new-lines
:s/"/\r/g
" Save
:w
Наконец, вы можете сделать это в функции с циклом for, но я оставлю это кому-то другому, чтобы написать!