Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
MrPablo
Mar 21, 2003

Hughmoris posted:

Is there a simple way to copy all regex matches in a file, and paste it into a new buffer? If not, maybe highlight all matches and delete anything that is not a match?

You can use :g/regex/d to delete lines that match a regex, like so:

code:
> echo old.txt:; \
  cat old.txt; \
  vim old.txt +:g/^delete/d +:w\!\ new.txt +:qa\!; \
  echo new.txt:; \
  cat new.txt 
old.txt:
delete a
keep a
delete b
keep b
new.txt:
keep a
keep b
It's probably better to just use grep though:

code:
> echo old.txt:; \
  cat old.txt; \
  echo grep:; \
  grep '^keep' old.txt 
old.txt:
delete a
keep a
delete b
keep b
grep:
keep a
keep b

Adbot
ADBOT LOVES YOU

  • Locked thread