How do I change existing surrounding quotes to parentheses with vim-surround?
Answer
cs"(
Explanation
The cs operator in vim-surround (change surrounding) swaps one pair of delimiters for another without touching the content inside. It is one of the most-used operations in the plugin: position the cursor anywhere inside the delimited region, type cs followed by the old delimiter character then the new one.
How it works
cs— the "change surrounding" operator- First character — the existing delimiter to replace (e.g.
",',(,[,`) - Second character — the new delimiter to use
Open vs close bracket behavior: when the new delimiter is an opening bracket ((, [, {), vim-surround adds a space on each side of the content. Using the closing bracket (), ], }) omits the spaces.
Example
"Hello, world"
cs"'→'Hello, world'(double to single quotes)cs"(→( Hello, world )(quotes to spaced parens)cs")→(Hello, world)(quotes to tight parens)cs"[→[ Hello, world ](quotes to spaced brackets)
For HTML tags, use t as the old delimiter: cst<p> changes any enclosing tag to <p>...</p>.
Tips
ds"(delete surrounding) removes the delimiters without replacing themysiw"(you surround inner word) wraps the word under the cursor in double quotesySiw"likeysiwbut places the content on its own indented line with the delimiters above and belowS"in visual mode wraps the selection in double quotes