Saturday, November 3, 2012

Re: search and replace using a list of characters to replace

On 11/03/12 14:11, Chris Lott wrote:
> I have a large text file in which I need to remove all punctuation,
> all special characters ("smart quotes") and the like, and a bunch of
> selected words.
>
> Can this be done within Vim?

Yes.

Oh, you want to know *how*? :-P

The smart-quotes are the hardest ones to do, but if you can enter
them in vim (or select+yank them, and then paste them into an Ex
command using control+R followed by a double-quote), they should be
usable:

:%s/\([[:punct:]]\+\|"\|"\|selected\|words\)//g

Alternatively, you might want to specify what *is* allowed and
invert it:

:%s/\W\+//g " that's "everything that isn't a Word character"
or
:%s/[^[:alnum:][:space]]\+//g "all but alnum & spaces"

which you can read about at

:help :alnum:
:help /\W
:help /\|

-tim




--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: