vimtricks.wiki Concise Vim tricks, one at a time.

How do I normalize curly quotes to straight quotes in the current buffer?

Answer

:%s/[“”]/"/ge<CR>:%s/[‘’]/'/ge<CR>

Explanation

When text comes from docs, email, or CMS exports, it often contains typographic quotes (“”‘’) that break code snippets, Markdown tooling, or shell commands. This two-step substitution normalizes both double and single curly quotes across the whole buffer in place. It is fast, repeatable, and safer than manual replacement because the e flag avoids noisy errors if one quote type is absent.

How it works

  • :%s/[“”]/\"/ge replaces every left/right curly double quote with a plain "
  • <CR> executes that first substitution
  • :%s/[‘’]/'/ge<CR> immediately runs a second substitution for curly apostrophes/single quotes
  • g means replace all matches per line, not only the first
  • e suppresses pattern not found errors so the command stays clean on mixed files

Example

Before:

He said “Ship it” and then wrote ‘done’.
It’s ready for “production”.

Run:

:%s/[“”]/"/ge
:%s/[‘’]/'/ge

After:

He said "Ship it" and then wrote 'done'.
It's ready for "production".

Tips

  • Add c to either substitution (/gec) when you want per-match confirmation.
  • If you prefer one line, you can join both substitutions with | interactively.
  • Use this after paste/import steps to keep source files ASCII-clean before commits.

Next

How do I paste the unnamed register after transforming it to uppercase?