How can I prevent keyboard binding from syncing in VS Code? - visual-studio-code

I use VS Code in Mac and Windows. All the sudden VS Code is trying to sync my key binding between the two. Is there a way to stop that?

You can disable the syncing of keyboard shortcuts using the command palette:
Press Ctrl+Shift+P to open command palette.
Type and select > Settings Sync: Configure...
Untick the option named Keyboard shortcuts
Hit the OK button in the top right and you should be good to go.

Related

How do I switch terminals in Visual Studio code using a keyboard shortcut?

I would like to be able to switch between terminal panes in VSCode using a keyboard shortcut. I am on a Mac.
I have opened keyboard shortcuts (Commandkey+K, Commandkey+S) and found the workbench.action.terminal.focusNextPane setting:
where it states quite clearly what the keyboard shortcut should be (option+command+downarrow or option+command+leftarrow) but neither of those work. They DO work when focus is in the editor and I want to switch between panes there, but not working when the focus in the terminal.
Not sure what I'm doing wrong but I hope I'm missing something obvious. Can anyone explain?
The commands you are looking at (Terminal: Focus Next Pane and Terminal: Focus Previous Pane) are to switch between split terminal panes.
The commands to switch between terminals are:
Terminal: Focus Next Terminal
workbench.action.terminal.focusNext
Terminal: Focus Previous Terminal
workbench.action.terminal.focusPrevious
both of which are unbound by default.

keyboard shortcut to switch focus in VSCode on a Mac?

Having a SQL file open in the editor, and psql running from the command line using the VSCode terminal, is there a keyboard shortcut to toggle the focus back and forth? I end up doing the CMD and the ` key to open/close the terminal but it'd be nice just to switch back and forth. Mac user.
Answering my own question: you can define workbench.action.terminal.focus in Keyboard Shortcuts (Preferences -> Keyboard Shortcuts) and then use that shortcut plus the CMD+1 to focus back on the editor (or CMD-2 etc). If someone has something more clever, let me know!

Can Visual Studio Code `quick fix` interact with keyboard?

I am using VS Code with the excellent vscodevim extension. When I navigate to a code that has a Quick Action available I can ctrl + . to activate the drop down context menu.
Is there a way to select toggle through the list of available items using the keyboard - other then the arrows keys. As a point of information, within Visual Studio it is possible using tab, this does not work in VS Code.
Why? 'cause I love my MS ARC keyboard but I hate the rocker arrow keys.
This is a known issue for linux users using vscode with advanced shortcuts like vim extension in your case, for some reason quick fix contextual menu is unattached from vscode shortcuts which makes shortcuts not work. A really easy workaround to use with a graphical interface is HotKey.
HotKey > https://github.com/autokey/autokey for Linux and create your own shortcut.

How to run the select code in VScode?

I want to run the select code of python in VScode. Till now, I have to copy the code and paste it in the terminal below to run. The system is mac OS.
So is there any way to run the code directly after I selected the code? For example, like the shortcuts.
Thanks.
There is no default keybindings for command "Run Selected Text in Active Terminal", but you can create one.
Press Ctrl+K, Ctrl+S to open File → Preferences → Keyboard Shortcuts.
Search for workbench.action.terminal.runSelectedText in keybindings.
Press the icon on the left to open a windnow with this message "Press desired key combination..." and make your choice. (I've pressed Ctrl+Alt+R - as this combination was not used yet.)
Press Enter to store your keybinding.
Tested on VSCode 1.30.2 on Windows 10 Pro.
#yanachen, this is now possible in VS Code. All you need to do is:
1. Ensure python is running in the VS Code terminal window
2. Select the text you wish to execute in python
3. Invoke the command 'workbench.action.terminal.runSelectedText' as defined in the following link:
https://code.visualstudio.com/docs/editor/integrated-terminal#_key-bindings
Now it's supported by default shortcut "shift" + "enter".
select the proper code snippet
press "shift" + "enter"
Here is the setting for running selection in "interactive window."
In my VS Code (version 1.56.2), I do the following things: go to Settings, search for interactive window, in the resulting left panel choose Jupyter, and finally check the box next to Jupyter: Send selection to interactive window. That's it. One more step for some users (including me) is to modify the keybinding for running selection to your preference. For example, got to keyboard shortcuts, type run selection, you should see a list of keybindings and you may need to redefine them if conflicts exist.
Some language specific extensions have already an existing keybinding.
On Windows, for the PowerShell extension it is currently F8 to run the selected text.
Install the vscode extension Node.js Exec. then select the block of code you want to run and press f8. worked for me.

How can I change keyboard shortcut bindings in Visual Studio Code?

Using Visual Studio Code what is the procedure to:
Remap a built in command's keyboard shortcut. For example, say, Open File (default is Ctrl+O, it's unlikely that anyone would actually change this, but the same process should probably apply for any built in shortcut).
Remap an extension command's keyboard shortcut, say the Bookmark extension's toggle-bookmark (default Ctrl+Alt+K)
IN 2015, this involved editing configuration JSON files, but I don't know which one, or how. In 2021 there's a new UI, how do I find it?
Click File -> Preferences -> Keyboard shortcuts. Use the tab that opens up to edit and find available key bindings and assign them.
Historical Note: In very early versions of visual studio code, you would Click File -> Preferences -> Keyboard shortcuts and you would get JSON like this keybindings.json:
// Place your key bindings in this file to overwrite the defaults
[
{ "key": "ctrl+o", "command": "workbench.action.files.openFile" },
{ "key": "ctrl+alt+k", "command": "bookmarks.toggle",
"when": "editorTextFocus" }
]
But now in 2021 versions, there is a proper GUI, which is great because the json editing method was error prone and hard to discover.
The json editor feature has been moved to a new icon:
If you want to change the advance settings of keyboard shortcut such as when then you can follow these steps:
Update:(Thanks #phdoerfler for pointing it out that icon has changed)
File->Preferences->Keyboard Shortcuts
Click on icon on top right corner that says "Open Keyboard Shortcuts(JSON)" to open JSON version and place the keybinding.
You can find this in Documentation here.
The way to open the JSON file changed yet again in a recent version.
You need to click the middle of the three buttons in the tab bar.
You only need to do that if the change you need isn't possible on the normal settings screen.
On Windows:
go to File -> Preferences -> Keyboard shortcuts,
or press Ctrl+K, then Ctrl+S,
or edit %UserProfile%\AppData\Roaming\Code\User\keybindings.json file
On Mac:
go to Code -> Preferences -> Keyboard shortcuts,
or press Cmd+K, then Cmd+S
Keep in mind you can type things like shift ctrl c in the Search input in Keyboard Shortcuts panel to find commands by their keybindings.
Here you can find documentation which among other stuff contains also information about what When conditions you can use.
The latest version of Visual Studio Code 1.11.0 provides a rich and easy keyboard shortcuts editing experience using a new Keyboard Shortcuts editor. Read more here on their website.
I will not repeat others answers! And if like me! You get to install a mapping extension!
My prefered is Visual studio keys map
And the question would have been how you select it! How you change it ! Can we install multiples! And select between them!
First here some useful links about key binding and shortcuts
https://code.visualstudio.com/docs/getstarted/keybindings
https://code.visualstudio.com/docs/getstarted/tips-and-tricks
And before any, know that you can get to the keymaps extension by using the bottom left settings button for settings context menu! As in the picture bellow:
or through file>Preferences>keymap
Then you have to install one of the keymaps
The thing to know is that it will take place and make the changes right away!
What if you install another?
The new one take over! Or some mix! I couldn't tell!
And you may have problems!
How you change from one to another?
Remove the old ! remove the new one! And install it again! That's the way that i found it works! Disabling and reenabling didn't work!
And better always let only one installed at a time!
Unfortunitly as by Now 2020-05-08 no options to select between keys mapping exist!
Undo a keymap
Just remove! You may need to restart the editor!
Restart the editor
Also note that if you uninstalled all and reinstalled the one you want! And changes didn't take place! Close the editor and reopen it! That's help!
I hope that's help and may be save you some searching time!
And sure in the future we will have better handling! As vscode is just keeping getting more awesome and awesome! So an option to select and better handling will is expected to be added! And we will wait for it!
FYI on mac the keybindings.json file sits there:
/Users/your_user_name/Library/Application Support/Code/User/keybindings.json
ctrl + shift + p
Type open keyboard shortcut in the search bar
It opens keyboard Shortcuts. Here you can customize shortcuts.
(For extra info follow from 4th point)
There at the top right corner click on open keyboard shortcuts (JSON) (Refer to the image)
There you can modify the key, command, and when. That is also cool.
I tried
{
"key": "ctrl+a",
"command": "workbench.action.terminal.selectAll",
"when": "terminalFocus && !isMac"
}
by this now I can select all in vscode terminal
On Windows: Ctrl + K, then S
On Mac: ⌘ + K then ⌘ + S
This opens Keyboard Shortcuts Editor. It's searchable/filterable by either shortcut name or the key combination itself (example: type "ctrl" to see all bindings to the CTRL key.)
Image:
vscode search keyword shortcuts panel
Open Key Shortcuts from Preferences -> Keyboard Shortcuts
Search for the action in search field
Right click on one of the results and select "Show same keybindings"
Delete the conflicting key binding!