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

In my current work of refactoring a fairly large codebase, I find myself wanting to replace apostrophes and quotes with each other from time to time.

Up until now I've been applying s/"/'/g for visual selections I've made, and it works fine.

Recently though, I discovered the tilde (~) command. I thought it would be nice if I could expand its functionality to not only change the case of characters, but also exchange " with ' and vice versa. Is it possible to expand its functionality to accomplish this?

share|improve this question
Have a look at the vim-surround plugin. With the plugin loaded you can change double to single quotes with cs"' (change surrounding from " to '). – Marco May 8 '13 at 11:11
That"s a great concept, it might even prompt me to look in vim plugin writin". – msw May 8 '13 at 13:54
I mean "you should get a software patent on the idea; profit!". ;) – msw May 8 '13 at 13:55
@msw: I was actually thinking about that too, but I was hoping there would be a simpler way to do it. – professorsloth May 8 '13 at 14:08

As @Marco points out in the comments, you're probably looking for the surround plugin. Using this plugin you can change the surroundings of text. For example:

"Hello World"

Got inside of the text and pres cs"' and the surroundings will change to

'Hello World'

I would also recommend Tim Pope's pathogen plugin to use to get everything set up. It will also install the help pages. The details on on the github page.

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.