Two ways of doing this are:

## With a `:substitute` command

    :%s/\(foo\)/\r    \1/g

The `\(` and `\)` around the search expression `/foo/` capture the match into a group, and then the `\1` uses the captured group in the replacement.

## With a `:global` command

You can also do this with the `:normal` and `:global` commands. For example the following command will indent all lines that match the regexp `/foo/` and add a line above them:

    :g/foo/normal >>O

This works similar to a `:substitute` command, but instead of making a substitution, it applies the normal mode operation `>>` followed by `O` to each matching line.

You can adjust the normal mode commands to perform different operations as necessary.

For more details:

    :help :global
    :help :normal