I know
g/PATTERN/m $
will move all the texts with matching PATTERN to the end of the file. How do I accomplish the opposite? (i.e. to the top of the file)?
Change $ to 0
:g/PATTERN/m0
If you want it in the same order as they are in the file run the command twice.
Or all at once. execute is needed since g can not be chained with bar. The second g command will use the same pattern as the first.
:exec 'g/PATTERN/m0' | g//m0
the command after the global command is :move which moves the current line to whatever address is supplied to move. 0 represents the first line in the file and $ represents the last.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With