Preserve formatting when rewriting lines