Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Vim how do I efficiently search and replace “ and ” with normal double quotes "

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.

like image 692
Jesus Nana Avatar asked Apr 13 '17 06:04

Jesus Nana


People also ask

How do you replace a double quote in Vim?

You'd use cs'" to change surrounding quotes.

How do I find and replace in Vim?

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.

How do I surround text with quotes in Vim?

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.


2 Answers

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

like image 72
mucka Avatar answered Sep 17 '22 16:09

mucka


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.

like image 29
Sash Sinha Avatar answered Sep 19 '22 16:09

Sash Sinha