vim Merge every string after hash above everything to the left, see preview for explanation :%s/\(.*[^ ]\+\) *\(# .*\)/\2\r\1/"