Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

I know this is gonna be a stupid question, but I've tried here, google and the official documentation.

I've got a file with a whole heap of words of the form 'foo' and i want to change them to Literal('foo'). The following :s command :%s/'.*'/Literal('.*')/gci finds the things i want to change but then it replaces them all with Literal('.*') rather than Literal('foo')

I get:
'_' -> Literal('.*') 
'dog' -> Literal('.*') 
I want: 
'_' -> Literal('_') 
'dog' -> Literal('dog')
share|improve this question
up vote 4 down vote accepted

You almost have it


You need to save the match and reference it in the replace. You were inserting a literal (no pun) .* in the replace.

share|improve this answer
Wonderful. Thanks so much. – user191304 Dec 28 '13 at 4:59

An alternative to casey's answer with explicit capturing is to restrict the match with \zs (start) and \ze (end), to assert that the single quotes are there, but don't include them. Then, you can just refer to the match in the replacement part with &:

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.