renga_in_stack
renga_in_stack

Reputation: 196

How to indent even/odd numbered lines of a text file using vim

I wanted to indent only even numbered lines in a text file using vim. In vim manual, indentation techniques are mentioned. But this will work either for a range of lines or particular line in which cursor positioned. I need a single command that should align the whole file. Is this possible in vim. Shall someone suggest on this.

Upvotes: 3

Views: 1108

Answers (1)

builder-7000
builder-7000

Reputation: 7627

To indent even lines:

:g/^/if line('.') % 2==0 | norm! >> | endif

to indent odd lines replace 2==0 with 2!=0.

Upvotes: 7

Related Questions