VSC keybindings - visual-studio-code

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.

Related

How to make backspace behave as backspace in 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

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:

How do I navigate to the next squiggly in the current file or project?

Often when I make bigger refactorings in my TypeScript codebase, I'd like to be able to navigate to the next underlined TS compiler error to fix it, then move on further etc. If I use "go to next problem" that always triggers a relatively big red popup message around that line. I would prefer for the cursor to simply jump to that position, I don't require any extra navigation etc. Is that possible?
If you don't get a simpler answer I think you may need a macro to do this so two commands are triggered. Using a macro extension like multi-command, put this in your settings:
{
"command": "multiCommand.nextError",
"sequence": [
"editor.action.marker.nextInFiles",
"closeMarkersNavigation",
]
},
and then in keybindings.json:
{
"key": "F8",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.nextError" },
"when": "editorFocus && !editorReadonly"
},
{
"key": "f8",
"command": "-editor.action.marker.nextInFiles",
"when": "editorFocus && !editorReadonly"
}
I get a quick flash when the next marker closes so this is not optimal but may be the best you can do.

Auto-add quotes around new lines in VS Code like Netbeans does

Just about completed my transition from Netbeans to VS Code, and there's one thing missing from VS Code that I miss dearly from Netbeans that essentially handles quotes automatically when you press enter from within a string.
These pictures should show what I mean, with this first picture being a lengthy string inside of Netbeans.
And this one is after I press enter somewhere in the middle of the string without pressing any other keys
You can see that it puts a quote where the cursor was, adds a newline, adds indentation, adds a dot (the PHP concat operator), and then another quote, which is such a fantastic feature.
Two things; what is this called, and how do I get this behavior in VS Code?
Pretty easy to do with a macro. Install the macrosRE extension.
In your settings.json:
"macros": {
"netbeans": [
{
"command": "type",
"args": {
"text": "\"\n\t\t. \""
}
}
]
},
and set up some keybinding for it in keybindings.json:
{
"key": "ctrl+alt+n",
"command": "macros.netbeans"
},
It would really interesting if there was a "when" condition to detect if within a string (and within a php file) ...and then bind to Enter. But I doubt there is such a "when" clause.
[EDIT]:
I should have remembered that in your case the 'macro' is so simple that you don't need to use the macro functionality. Try simply this in your keybindings.json:
{
"key": "ctrl+alt+n",
"command": "editor.action.insertSnippet",
//"when": "editorTextFocus && editorLangId == php",
//"when": "editorTextFocus && resourceLangId == php"
"args": {
"snippet": "\"\n\t\t. \""
}
}
It just inserts a snippet which is right there in the args. You may or may not want the 'php' limitation. You can also use the method below if you want to insert a snippet that actually lives in a snippets file:
{
"key": "cmd+k 1",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"langId": "csharp",
"name": "myFavSnippet"
}
}
From vscode doc: assigning a keybinding to a snippet.
But you will eventually want to chain commands together which the macros extension allows you to do.