- MrPablo
- Mar 21, 2003
-
|
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
|
#
¿
Sep 17, 2015 04:23
|
|
- Adbot
-
ADBOT LOVES YOU
|
|
#
¿
May 7, 2024 10:05
|
|