Pattern-matching in vim solves my problem

I am gradually migrating passwords out of my old encrypted passwords.txt and into pass, as detailed here. Just so I can keep track of what has migrated and what has not, I prefix each migrated line in passwords.txt with the text "===". But these migrated lines are scattered all over a 700-line file. How can I gather the lines in one place so that I can quickly scan what I have migrated?

Using vi's pattern-matching rules, that's how. The following command matches all the lines prefixed with "===" and moves them to the bottom of the file.

:g/^===/m$

Why to the bottom (m$) and not the top (m0)? Because this preserves the lines' ordering, so any multi-line entries stay in their original order and are easier to read.

Leave a Reply

Your email address will not be published. Required fields are marked *