Tip 93: Rearrange CSV Fields Using Submatches
Return to the top: <<Practical Vim>>
-
reference submatches using
\n
Example:
last name,first name,email neil,drew,drew@vimcasts.org doe,john,john@example.com
swap the order of the fields so that the email comes first, then the first name, and finally the last name:
/\v^([^,]*),([^,]*),([^,]*)$ :%s//\3,\2,\1