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/rewill print at the bottom of the screen all lines matching patternre(default commandpis used here):g/pattern/normal @aplays theamacro on all lines matching pattern:g/pattern/normal A.appends a dot.on all lines matching pattern:g/console/g/two/dis an example of recursive commandconsolefirst matches lines containingconsole- and then second g filters out matches containing
twofrom the earlier matched - then applies
dcommand
:g/pattern1/,/pattern2/commandmakes Vim will apply the command within pattern1 and pattern2/^$/matches empty lines (with no character):g/^$/,/./jbasically 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@ddeletes all lines containing console
- g and s command can be conviniently combined
:g@one@s+const+let+gmatches lines containingone- and then uses the substitute to replace
constwithlet(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 patternTODOat 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 patternconsoleand puts them in black hole register_