Goat command
Command structure resembles substitute command- :g/re/command
will run command
over all lines (not words) matching the regular expresson pattern re
:g/re
will print at the bottom of the screen all lines matching patternre
(default commandp
is used here):g/pattern/normal @a
plays thea
macro on all lines matching pattern:g/pattern/normal A.
appends a dot.
on all lines matching pattern:g/console/g/two/d
is an example of recursive commandconsole
first matches lines containingconsole
- and then second g filters out matches containing
two
from the earlier matched - then applies
d
command
:g/pattern1/,/pattern2/command
makes Vim will apply the command within pattern1 and pattern2/^$/
matches empty lines (with no character):g/^$/,/./j
basically matches empty lines (^$
) and non empty lines (.
) and joins them (j
)
- Delimiter can be changed like the substitute command, use any character except for alphabets, numbers, ”, |, and .
:g@console@d
deletes all lines containing console
- g and s command can be conviniently combined
:g@one@s+const+let+g
matches lines containingone
- and then uses the substitute to replace
const
withlet
(last g for applying substitute on all matches within the matched lines) - could also use
g/one/s/const/let/g
:g/TODO/t $
copies all lines matching patternTODO
at the end of file (:h :copy)- Invert also works
:g!/TODO/t $
copy everything except TODOs at end of file :g/TODO/m $
moves all TODOs instead of copying them
- Invert also works
:g/console/d _
deletes all lines matching patternconsole
and puts them in black hole register_