Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Vim, I'm trying to run a substitution on this text:

lorem ipsum -- dolor sit get it to look like this:

lorem ipsum—dolor sit

I'm trying to do :%s/ -- /—/g, but it leaves me with this:

lorem ipsum -- —dolor sit

How should I adjust my substitution syntax?

share|improve this question
Easy fix--I just needed to escape the ampersand: :%s/ -- /\—/g – Joe Mornin Jan 17 '12 at 16:23
are you not allowed to give yourself an answer (instead of a comment)? – akira Jan 17 '12 at 16:59
@morninj your ampersand is not even in your substitution string. Did you forget it in your question? – tidbeck Jan 17 '12 at 19:58
@akira Since I'm below a reputation threshold, I have to wait 8 hours before adding an answer. – Joe Mornin Jan 17 '12 at 20:59
FYI, vim-textcov has some functions to do this for you. – idbrii Dec 5 '12 at 18:10
up vote 2 down vote accepted

Easy fix--I just needed to escape the ampersand: :%s/ -- /\—/g

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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