How to make backspace behave as backspace in Visual Studio Code - visual-studio-code

In Visual Studio Code I indent using two manually inserted blanks. When I press backspace this deletes two blanks at the same time.
How can I turn off this behavior? I want a backspace to "eat up" exactly ONE blank, especially if the blank is a blank and not a tab.
The question is just the opposite to Deleting tabs when using tabs as spaces.

with extension multi-command you can create a keybinding that does what you want
add to keybindings.json (at the end) this will overrule the default backspace behavior
{
"key": "backspace",
"command": "extension.multiCommand.execute",
"when": "editorTextFocus && !editorHasSelection",
"args": {
"sequence": [
"cursorLeft",
"deleteRight"
]
}
}
Edit
Added && !editorHasSelection to get the default behavior when there is a selection

Related

VSCode how to know when editor is not split?

Until now, I used cmd+2 to split the editor on Visual Studio Code and then cmd+1 and cmd+2 to move between the split editors. This shortcut stopped working for some reason, and I can't set it on the keyboard shortcut menu either.
I checked with another keyboard, so this is not an hardware issue.
Anyhow, I tried to set new keybindings to split the screen and move between the editors, like this:
[
{
"key": "cmd+shift+]",
"command": "workbench.action.navigateRight",
"when": ""
},
{
"key": "cmd+shift+]",
"command": "workbench.action.splitEditorRight",
"when": ""
},
{
"key": "cmd+shift+[",
"command": "workbench.action.navigateLeft",
},
]
The only problem, I couldn't find what I need to write in the when option.
I want my shortcut to split the editor only if the editor is not split yet, and to move between the editors when it is.
How can I achieve that?
The multipleEditorGroups when clause context returns true when there's more than one editor group open.
You don't need to put a "when" for neither of them. Just checked vscode defaults and they don't have any.

VSCode jump to the middle of current line

There are many keyboard shortcuts and edit options in Visual Studio Code, I can move cursor: by character, by word, to beginning/end of line. But, if I'm editing a long line of text, how to faster jump to the middle of this line ?
Found similar question here, but for vim users - Visually select to the middle of line
Probably, it's possible to implement this option (jump to middle) with Vim extension. If so, then how to do it ?
Is there a way to make such behaviour natively without any extensions ?
Actually, this is built-in to vscode, using the cursorMove command. Set up this keybinding in your keybindings.json:
{
"key": "alt+c",
"command": "cursorMove",
"args": {
"to": "wrappedLineColumnCenter",
"select": true // default is false
}
}
You can use the extension Select By v1.0.0.
You can create a keybinding that calculates the new cursor position
{
"key": "ctrl+i ctrl+m", // or any other key binding
"when": "editorTextFocus",
"command": "moveby.calculation",
"args": {
"charNrEx": "currentLine.length / 2"
}
}

Move cursor to the beginning of the multiple selected lines visual studio code

How do you move your cursor to the beginning of multiple selected lines in VScode ? i know that shift+alt+i is to go the end of the line but couldn't find the reverse. Don't confuse my question with the start of the document.
You can create a keybinding that uses a macro extension to run multiple commands, like multi-command
{
"key": "home", // whatever keybinding you wish
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"editor.action.insertCursorAtEndOfEachLineSelected",
"cursorLineStart" // goto start of line before any leading whitespace
// "cursorHome" // goto start of text on each line
]
},
"when": "editorTextFocus && editorHasSelection"
}
It works really nicely, with one multi-line selection or multiple selections:

VSC keybindings

I have tried to implement this feature for a long time. I have not been able to find answers online. I would like to use "Tab" key to do two things.
I want to indent if cursor is at the beginning of a line, or
jump to end of line if cursor is between characters/strings.
[
{
"key": "ctrl+tab",
"command": "tab",
"when": "editorFocus && inputFocus && !editorHasSelection"
},
{
"key": "tab",
"command": "cursorEnd",
"when": "textInputFocus"
}
]
These are similar features that are in Eclipse and Intellij IDE
You should be able to achieve this by modifying the extension TabOut, which indents except when the cursor is next to a bracket or brace, in which case it tabs through.
If you instead of a brace, you make it behave that way next to any character except newlines, it should jump to end of line.

Disable closing bracket swallowing? [duplicate]

This question already has answers here:
How to make vscode stop overriding closing parentheses on insertion
(5 answers)
Closed 3 years ago.
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.
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.
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.
TL;DR: currently it is not possible to disable this annoying feature.
I'v asked the same question here.
There is an open issue in their repo.