The following assumes a basic familiarity with the Vim
:substitute command. First replace the whitespace characters with underscores.
: while text is visually selected will automatically fill in
\%V before and after the space cause the enclosed pattern (the space) to match only within a visually-selected region. Next remove the non-word characters. Type
gv to re-select the region. Then type
\W is a Vim regex atom meaning "non-word character." See
\%V can be awkward. The vis.vim plugin simplifies this by allowing one to execute any ex command on a visually-selected region by typing
B then the ex command, simplifying the above to
where again, Vim fills in the
'<,'> part for you.
I replaced "space" with "whitespace characters" above after re-reading the question.