0

I have a news article which I need to edit up a bit. Basically, I need to search for all lines that do not contain characters t and h 2 or more times in a row and replace 4 letter words with character D in those lines. Have no idea where to start. For example, I have this text

Animals are multicellular eukaryotic organisms which form a biological kingdom Animalia. 
Historically, Aristotle divided animals into those with blood and those without

And I want it to look like

Animals are multicellular eukaryotic organisms which D a biological kingdom Animalia.
Historically, Aristotle divided animals into those with blood and those without

1 Answer 1

1

Not too hard, really, as such tasks can be translated into regexps in a very straightforward manner.

:v/tt\|hh/s/\<\a\{4}\>/D/g

:v/.../ for all lines NOT matching a pattern

tt\|hh "tt" OR "hh"

s/.../D/g substitute ALL matches on a line with "D"

\<...\> "word" borders

\a\{4} exactly four Latin letters

Have no idea where to start.

Read about regexps. In Vim's embedded help these are :h usr_27.txt and :h pattern.txt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.