It is possible to delete all lines matching a pattern using :g/pattern/d.

Using the following command, you can replace words matching a pattern, 20 lines after where the cursor currently is: :s/pattern/changed_pattern/g20

How do you delete all lines matching a pattern, but N lines after where the cursor currently is ?

I've tried : 34,50/pattern/d however it delete backward, and inconsistently. Beside, it requires you to know exactly the lines between which to apply the deletion.

  • 1
    Can you please provide a short example input with the expected output?
    – Quasímodo
    Jul 17, 2020 at 20:00
  • What do you mean by "backward" and "inconsistently"? An example of what you're seeing and what you expected might help...
    – filbranden
    Aug 16, 2020 at 19:58

1 Answer 1


These commands should do the trick


The key is to understand [range] for delete command.

  • .+1 one line after cursor line
  • .+N N lines after cursor line
  • \/+1 one line after current match
  • \/+N N lines after current match

See :help cmdline-ranges for more details.

Be aware it will delete pattern if it is in N lines range!

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .