0

I would like to edit some text before dumping it into the Vim buffer.

I retrieve the content of a webpage with :r! w3m -dump someurl.com.

I would like to delete everything in the returned text from the beginning until the word "table of contents", including that word.

How can I send the output of the :r! to an :s command (or similar) so that I can match and delete this pattern in one line of code?

2
  • 1
    Why do you want to do the substitution before you write to the buffer? You could write your page to the buffer, use the power of vim to modify your buffer and then save it. That would make the workflow more efficient since you leverage all the capabilities of vim.
    – statox
    Sep 17 at 10:57
  • 1
    Also I think this question might be a duplicate of other questions we already have on the site about how to redirect the output of a command to a variable like this one since you will have to get the result in a variable and apply substitute() on the variable. The "Redirect :r! to :s" is a XY problem.
    – statox
    Sep 17 at 11:04
1

If you want to automate this process I would go with regular vimscript + vim api:

let output = system('w3m -dump someurl.com')
let output = substitute(output, 'regex', 'replace', 'g')
" do smth else with output
"...
"...
" append output to the current buffer after current line
call append('.', split(output, '\n'))

If you really want to send the output of :r! command to :s for some other reason, I don't think there is a simple way to do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.