Search code examples
vimvi

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.


Solution

  • To indent even lines:

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

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