How to delete every other line in Vim?

前端 未结 12 1398
天涯浪人
天涯浪人 2020-12-04 06:13

I would like to delete every other line from a Vim buffer, starting with the second one, i.e., lines 2, 4, 6, etc. For example, if the buffer’s contents is:

a         


        
12条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 06:55

    from vim mail archive:

    :let i=1 | while i <= line('$') | if (i % 2) | exe i . "delete" | endif | let i += 1 | endwhile
    

    (To be typed on one line on the vim command line, will delete row 1,3,5,7,...)

提交回复
热议问题