4

I want to indent lines in each paragraph except the first one.

By paragraph, I mean a group of lines that are separated from other groups of lines by at least one blank line.

For example, here we have three paragraphs:

paragraph1
line1.1

paragraph2
line2.1
line2.2

paragraph3

I want to indent all the lines except the first one in each paragraph. To do this, I use the following command:

g/^\w\+/+1,/^\s*$/>

The problem is that this command indents every line progressively. The result is as here:

paragraph1
    line1.1

paragraph2
    line2.1
        line2.2

paragraph3

line2.2 is indented twice. I guess this occurs because global command matches all lines first with the regex ^\w\+, then it applies the command +1,/^\s*$/>.

How can I produce the following output?

paragraph1
    line1.1

paragraph2
    line2.1
    line2.2

paragraph3
2

If you don't mind the error message (of the the +1 going past the last line), just doing

:g/^\w/ +>

works. Since the pattern for :global matches all the lines below paragraph2 anyway, there is no need to give range to :> at all (besides the +1 to skip the first).

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.