I got this code snippet from a tutorial and I would like to search and replace all occurrences of “ and ”, with normal double quote ". How can I efficiently do it in Vim?
{
“runtime”: {
“DDP_DEFAULT_CONNECTION_URL”: “http://127.0.0.1:8100”
},
“import”: [
“[email protected]”,
“[email protected]”,
“[email protected]”,
“[email protected]”,
“[email protected]”,
“[email protected]”,
“[email protected]”,
“[email protected]”,
“[email protected]”,
“[email protected]”
]
}
Thank you.
You'd use cs'" to change surrounding quotes.
The simplest way to perform a search and replace in Vim editor is using the slash and dot method. We can use the slash to search for a word, and then use the dot to replace it. This will highlight the first occurrence of the word “article”, and we can press the Enter key to jump to it.
press q and q for recording into q register (we use "q" as shortcut to remember "quotes"). press a then press ' again to surround the word with quotes.
You can show ascii code of character using ga in normal mode.
You can also put arbitrary utf8 code using Ctrl+vuhhhh for characters with code 0000 <= hhhh <= FFFF and Ctrl+vUhhhhhhhh for the rest in insert mode and command mode so when starting in normal mode you need to type, similar to @shash678 answer:
:%s/Ctrl+vu201c/"/g
In command-line mode you can use the following command to find each occurrence of “ and ” (in all lines), and replace them with ":
:%s/[“”]/"/g
EDIT:
To do this, (assuming you have the file open in vim):
1) hit the ESC key to ensure you are Normal mode.
2) hit : , you will notice : has appeared in box at the bottom of vim (that is the command line).
3) type the rest of the command for finding each occurrence of “ and ” (in all lines), and replacing both with ".
4) hit the ENTER key.
5) your done! The command line will say something like made 56 substitutions on 13 lines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With