How to delete every other line in Vim?

An elegant (and efficient) way to accomplish the task is to invoke the :delete command (see :help :d) for the + line range (same as .+1) addressing the line following the current one (see :help {address}), on every line (see :help /^) using the :global command (see :help :g):

:g/^/+d

We can use the :normal (or :norm) command to execute the j and dd Normal-mode commands:

:%norm jdd

Source: the Best of Vim Tips page by zzapper.


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.

Tags:

Vim