Reputation: 13
I have a text file containing two or more types of lines. I would like to separate it into two different files. I do that with this list of commands :
:%g/myregexpforlinetype1/ . w >> file1
:%g/myregexpforlinetype1/d
:w file2
But I think it is not optimal. How could I make this more generic, more robust, more efficient ?
Thanks
Upvotes: 1
Views: 90
Reputation: 11788
You can use the fact that :v
matches all lines not matching a search expression combined with the fact that //
will repeat the previous search:
:%g/myregexpforlinetype1/ . w >> file1
:%v// . w >> file2
Upvotes: 1