string - Moving Columns/Text in VIM -
i wondering how might go moving around columns/text around in vim using string. have short list of names have reorder, need placed in last name first middle first middle last.
so here example list:
- plant, robert a.
- page, jimmy
- bonhham, john h.
- jones, john paul
i thinking string should this:
:s/\([a-z]\{2}\)\(\[a-z]\{2}\)/2\1/ thanks
first, recommend using \v "very magic" flag avoid other internal escaping of metacharacters. work replacement like:
:s/\v([a-z]+),\s+([a-z]+)(\s+[a-z.]+)?/\2\3 \1 breaking down:
([a-z]+)capture last name\1,\s+literal comma , 1 or more spaces([a-z]+)capture first name\2(\s+[a-z.]+)?capture middle name with leading spaces, since may not exist. permit., , end?make whole construct optional,\3\2\3 \1replace second group (first name) followed middle name\3no space in between because space captured along middle name. append\1last name.
if names possibly more [a-z]+, may alternatively use [\s]+ capture non-whitespace characters.
Comments
Post a Comment