How to delete every other line in Vim?

前端 未结 12 1403
天涯浪人
天涯浪人 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:48

    You can use a macro for this. Do the following.

    • Start in command mode.
    • Go to the beginning of the file by pressing gg.
    • Press qq.
    • Click arrow down and press dd after.
    • Press q.
    • Press 10000@q

    PS: To go to command mode just press Escape a couple of times.

提交回复
热议问题