We can use m to move lines around, and j to join lines. For example if you have a list and you want to separate all the stuff matching (or conversely NOT matching some pattern) without deleting them, then you can use something like: :% g/foo/m$ ... and all the "foo" lines will have been moved to the end of the file. (Note the other tip about using the end of your file as a scratch space). This will have preserved the relative order of all the "foo" lines while having extracted them from the rest of the list. (This would be equivalent to doing something like:
1G!GGmap!Ggrep foo<ENTER>1G:1,'a g/foo'/d
(copy the file to its own tail, filter the tail through grep, and delete all the stuff from the head).
Going through the this legendary answer by Jim Dennis but I still can't get my head around this sequence:
1G!GGmap!Ggrep foo<ENTER>1G:1,'a g/foo'/d
Someone help elaborate, what is GGmap? Why's there a bang between 1G! GGmap? Does Ggrep come from vim-fugitive?