There is a better way of accomplishing the task you showed in ex mode, which is by using the :delete
command and a basic cmdline-range
. To delete all lines between and including the beginning of the file and the search match, you can do this:
1,/dd/delete
If you don't want to include the matched line in the deletion, you can do this
1,/dd/-1delete
The first one works by selecting a range between the first line of the file and the first line that matches the pattern dd
, which is then used by the delete command. The second one is essentially the same, except there is a -1
before delete
which selects the line directly above the pattern dd
.
For more on this, see cmdline-ranges
.