How to use another command after `norm` in `:global`?

Viewed 82

For example, I have some HTML <p> with several sentences and want to extract the content and put each sentence in its own line. I want this for all paragraphs in one command run.
So from:

<p>Hello. This is Alan. I am a wookie.</p>

<p>Hello. This is Bob. I am an ewok.</p>

I want to get:

Hello.
This is Alan.
I am a wookie.

Hello.
This is Bob.
I am a ewok.

I can extract all <p> contents by running :g/<p>/norm ditVp. I can also place my cursor in such extracted paragraph and run :s/\.\s\?/.\r/g to split them all. How can I merge this in one command?

1 Answers

Usually, when we want to have multple commands in one line then we use |.
But you are performing :g and then withing it :norm. As we read in :h :bar both of them treat | as their argument. In such situation we use :execute.
Since we want for the :s to be part of :g, then we will enclose :norm in :exec like so:

:g/<p>/exec "norm! ditVp" | s/\.\s\?/.\r/g
Related