As always, in vi
there are many ways to skin this particular cat. As has already been stated, a simple solution to exactly this problem is:
:%s/HERE.*//
However, to answer your more general question:
I have done search and replace things in vi, but am not sure how to do a search then run a command.
you want the :g[lobal]
command:
:[range]g[lobal]/{pattern}/[cmd]
Execute the Ex command [cmd] (default ":p") on the lines within [range] where {pattern} matches.
This would actually be more long-winded for your exact example, but for tasks such as deleting lines that match a specific pattern, it is considerably more concise.
e.g. if you wanted to instead delete all lines that contain HERE
, you would run:
:g/HERE/d
Factoid: this command form is the origin of grep
's name: g/re/p
, shorthand for global/{regex}/print
.