How to delete every other line in Vim?

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

    You can always pipe though a shell command, which means you can use any scripting language you like:

    :%!perl -nle 'print if $. % 2'
    

    (or use "unless" instead of "if", depending on which lines you want)

提交回复
热议问题