Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable closing bracket swallowing? [duplicate]

When you have the cursor in front of a ], ) or } and you type that character, instead of inserting it vscode just moves past that character, producing ]*cursor here* instead of ]*cursor here*]. Becacuse of this, every time I actually need to insert a closing bracket I need to move to the end of the )))) to type it, instead of just being able to type it directly. So is there a way to disable this behavior(without disabling bracket auto-completion)?

Here is the same question, but for sublime text, and this guy mentions it as a side effect of auto-closing brackets.

like image 310
alvitawa Avatar asked Oct 05 '17 15:10

alvitawa


2 Answers

I received a solution from github of vscode project.
It works for me. Edit your keybindings.json add the text below:

{
"key": "]",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
    "snippet": "]"
}
},
{
"key": "Shift+]",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
    "snippet": "}"
}
},
{
"key": "Shift+0",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
    "snippet": ")"
}
}

Notice: "Shift+0" for en keyboard (, edit it for your keyboard layout.

like image 147
CL. Wang Avatar answered Nov 05 '22 07:11

CL. Wang


It is indeed a side effect of the autoClosingBrackets setting of the editor.

If you go to File > Preferences > Settings to open the settings JSON file, you can search for "editor" or "autoClosing" and copy the entry to your user settings if you whish to change/disable it (it's enabled by default), or just copy this to disable it:

// Controls if the editor should automatically close brackets after opening them
"editor.autoClosingBrackets": false,

More on VS Code settings, as well as a list of the default settings can be found here: https://code.visualstudio.com/docs/getstarted/settings

If you disable this setting:

  • Typing a bracket or quote won't automatically add a matching, closing bracket or quote.
  • Typing a (closing) bracket before an existing one won't cause it to be "absorbed".
  • You'll have to type each closing bracket or quote yourself.
  • You won't be able to automatically enclose selected text with brackets or quotes by selecting it and typing just one bracket/quote. With this option disabled, the selected text will be replace with whatever you type.
like image 4
z0ppa Avatar answered Nov 05 '22 07:11

z0ppa