Skip to content

Instantly share code, notes, and snippets.

@voyeg3r
Created August 29, 2017 14:00
Show Gist options
  • Save voyeg3r/9d4e295474143715a004d609fc37b46a to your computer and use it in GitHub Desktop.
Save voyeg3r/9d4e295474143715a004d609fc37b46a to your computer and use it in GitHub Desktop.

Insert blank lines only where there is not blank line

This solution will avoid double blank lines

:g/.\n\n\@!/norm o

The magic happens because we are denying a consecutive new line with \n\@!

Insert a blank line after each second line

:%s/^/\=(line(".")%3==0?"\n":"")/g

The first parentesis is a ternary operator wich will retun a new line "\n" or a blank line "" depending on the Mod of the line number line(".") by 3. In case it is true the beginning of line is substituted by a new line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment