Vim Cheatsheet
Add line above or below a certain character
For example, add a new line above/below every comment in code
:g/key/norm oTextToInsert(just leave “whatever you want” blank and use a capital O to add the line above!)
source also: all about the normal command
Regex match start of line only
Just add ^ to the start of the search. (Works well with the above normal command!) eg:
:g/^echo/norm Oecho.(this adds a newline echo above every echo command in the batch file, but NOT about @echo OFF lines.)
Remove all blank lines
:g will execute a command on lines which match a regex. The regex is ‘blank line’ and the command is :d (delete)
:g/^$/d