'Remove surrounded quotes in vscode or toggle between quote and no quote

Is there any shortcut or extension for vscode which can help to remove surrounded quotes (single ' or double " ) around a selected text?
See example below

'hello' ==> hello

In other words, is it possible to have a feature which will toggle current selection between quotes and no quotes?

I have tried es quotes for vscode which is very nice while switching the quotes between single and double quotes.



Solution 1:[1]

There is this extension that lets you do some tricks with selections between quotes. You can toggle between simple and double quotes, and you can select whatever is inside some quotes.

The most approximate solution which I found is to select all with the shortcut (Ctrl+k, `), then cut, erase the quotes and then paste the text.

That's the best I found

Solution 2:[2]

Elaborating on Soldeplata's answer:

Before we start: Look up your shortcut for expanding selection by hitting Ctrl+k,Ctrl+s and search for smartselect (as it could differ with keyboard layout and installed keymap-extensions). I have two shortcuts to choose from: Shift+alt+? or Ctrl+w

The steps (not one shortcut but a small series):

  • Your starting point..................................... Some say: "hello";

  1. Put cursor any where in the word hello
    and use shortcut to expand selection....... Some say: "hello";
  2. Cut selection (Ctrl+x)......................... Some say: "";
  3. Hit backspace once
    (this removes both quotes)...................... Some say: ;
  4. Paste (Ctrl+v).................................... Some say: hello;

Solution 3:[3]

Say you were given the following JSON and you want the researchers value to be an array instead of a string. We need to remove the quotes that are wrapping the array. In version 1.64 of VSCode, you can do this search and replace using the built-in search and replace regex capture groups (no extension needed).

[
  {
    "id": 2,
    "description": "Project 1",
    "researchers": "[12,5,22]"
  },
  {
    "id": 3,
    "description": "Project 2",
    "researchers": "[1,44,22]"
  }
]

screenshot of search string in VS Code

In the search field you will want to use a regular expression of "researchers": "\[(.+)\]", where the (.+) part of the expression being the first group we want to preserve or leave unchanged when we perform the replace. Then in the replace field we use "researchers": [$1], with $1 corresponding to the (.+) first group we are preserving in the search string. What this means is that we take the values that were found in the first search group (which in the first instance is 12,5,22, then wrap it with "researchers": [12,5,22]. The replaced JSON becomes:

[
  {
    "id": 2,
    "description": "Project 1",
    "researchers": [12,5,22]
  },
  {
    "id": 3,
    "description": "Project 2",
    "researchers": [1,44,22]
  }
]

The following video is also helpful. https://www.youtube.com/watch?v=6AsSfyHWWls

Solution 4:[4]

I highlight the word with ctl+d and then type a quote. Same for parens or braces.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Soldeplata Saketos
Solution 2 Community
Solution 3
Solution 4 Angel Fernando