This is a follow-up to my question about using multi-line regex in Vim.
A quick explanation: I have blocks of text tagged with #tags and separated by a blank line. I want to filter out all blocks that include a specific tag. I was helped with regex here (thanks!), so I constructed the following command:
command -nargs=1 TagSearch g/^\(.\+\n\)\{-}.*#<args>.*/y a | vnew | put a | %s/^#.*<args>.*\n/&\r
Hence, doing a :TagSearch tag should:
- Search for the
#tag. - Paste all corresponding Text Blocks into a new vertical buffer.
- Add a blank line between the Text Blocks in the new buffer.
Q1: When I do each step separately, everything works. But the multi-command only pastes the first matching text block into the new buffer. Why?
Q2: How could I make the command accept multiple arguments (in case I want to search for several #tags at once)? Thanks!
One can use the following implementation.