How to add a line after every few lines in vim

vim

Solution

there is a vim-specific regular expression to do that

  :%s/.*\n.*\n.*\n/\0\r/g

- %s is vim ex command to substitute in the whole file

- .*\n is a line including the end of line

- \0 is the entire matched expression

- \r vim way to say add a new line (not \n as one would expect)

Edit: if you want anything else than a new line, just put the text in front of the \r (properly regex escaped, if it contains some regex characters)

Problem

I wanted to add a line after every 3 lines in a file (having about 1000 lines) using vim editor. Can someone help me out? Thanks, Alisha

Original source