regex

:s is the substitute command while :g is the global command. By default, :s works on the current line (where the cursor is at). But you can make it work on all lines with :%s or you can make it work on a region by visual selecting first before the :s.

:g is about executing an ex command on all the lines that match a particular pattern. While in :s you pass the regex that you want to substitute, in :g its the regex that will match the line that contains the pattern, and an ex command will be executed on that line. :h holy-grail to find the index of those commands.

Delete every line that begins with a digit:

:g/^\d/d

Delete all empty lines:

:g/^$/d

Comments