I used to able to comment or uncomment multiple lines of code by pressing ctrl+/
# x = 10
# print(x)
But now I press ctrl+/, it becomes the following:
...
I tried to search for solution online, and I believe it is because the Windows shortcut somehow overwrite the shortcut in VS code. But I cannot find a solution.
I tried:
1.Reset the shortcut
2.Reinstall VS code
They don't work. Any help is appreciated.
First of all see which keyboard layout you are using on your System. Change the Keyboard layout to US-Keyboard if US keyboard is not selected.
If it is US keyboard then,
The shortcut key might have changed.
You can edit your preferences on VS code.
Goto File > Preferences > Keyboard Shortcuts
Search for Toggle Line Comments.
Click on edit icon and press your desired shortcut key
It could also be caused due to the same key bindings for shortcuts.The Keyboard Shortcuts editor has a context menu command Show Same Keybindings, which will filter the keybindings based on a keyboard shortcut to display conflicts. To view same key bindings follow the above steps till Step 3.
Now right click on the Toggle Line commands and click Show same key bindings.
It depends on what language you are programming.
But if you want to type # character you can hold down shift key and press number 3 on your keyboard.
I encounter this problem before. You should press shift key to switch back to type English and try again.
Related
The default VS Code keybinding for toggling line comments isn't working in Jupyter Notebooks. The shortcut Ctrl+/ works fine when I use it in .py files, and it seems to work everywhere else as well. But when I am in a *.ipynb file, it just doesn't work. I noticed that when I use the browser VSCode version, the shortcut works in *.ipynb files.
I thought that changing the keybinding to something different might help solve the issue, but to no avail.
I tried recreating my project-environment. I recreated everything in new files, and in new folders. I even tried reinstalling VS Code. Nothing has worked for me.
VS Code Provides a Tool for Troubleshooting this Exact Issue
I have answered questions about VS Code Keyboard Shortcuts
several times, and what I learned from the experience, is that most people seem to prefer hitting there heads against a wall, rather than using the tool that VS Code developers graciously provided for them (or us I mean).
The Tool is named Keyboard Shortcuts Troubleshooter, and it is Toggled ON/OFF via a native VSC command. The command can be found in VS Code's "Quick Input Drop-down Menu". To execute the command, you need to open the Quick Input Menu using the F1 Key. Once the menu opens, your editor will change focus to its text-input, so you don't have to do anything other than simply typing the bold line of text below.
"Developer: Toggle Keyboard Shortcuts Troubleshooting"
While typing an option with the same name as what you are typing will appear in the menu. (PLEASE NOTE: _there are a few troubleshooters, one for keyboard shortcuts, and a couple others that pertain to Notebooks (DO NOT USE ANY TROUBLESHOOTER BUT THE KEYBOARD SHORTCUTS TROUBLESHOOTER).
Once you have found, and selected the "Developer: Toggle Keyboard Shortcuts Troubleshooting" command in the quick menu, the troubleshooter will be active.
PLEASE NOTE: SELECTING THE TROUBLESHOOTER TWICE WILL DEACTIVATE IT AND YOU WILL BE LEFT AT WHERE YOU STARTED.
To view the tool's output, you'll need to change your panel's view from terminal to the Output Console by selecting output at the top of your panel. Vs-code might automatically do this for you though. It didn't use to, but I think it does open the correct output window when you execute the +"Developer: Keyboard Shortcuts Troubleshooting"_ command. If it doesn't, then make sure you select LOG(Window) from the drop-down at the top-right of the Output-console's panel.
With the troubleshooter active, and the output open, use a keybinding (any keybinding) to test it. The output looks like this.
You Should have the Troubleshooter Working, which will give you all the info you need to understand the issue you have.
Bellow I have provided a snippet showing what the Output console looks like when I executed my custom Save-all Keybinding. So that your not completely on your own, your going to want to visit two links, if your able to be self-taught, these links golden.
The first is a guide. I provided this link, because if you can't get your troubleshooter working, this link provides a VS Code documented guide on how to use it. Plus a wealth of other info on this subject. [CLICK HERE]
The second is a Microsoft/VSCode/Wiki. Its covers this topic in a context that's has a little more depth to it. Over all I find this page very helpful, but it is a more advanced resource. [Click Here]
Click on the links that say CLICK HERE, the others go to the generic sites.
This output is for the keys:
[CTRL]+[SHIFT]+[SPACE] [S]
It saves all files when pressed. And this is the output for that keybinding I just described.
> / Received keydown event - modifiers: [ctrl,shift], code: Space, keyCode: 32, key:
> | Converted keydown event - modifiers: [ctrl,shift], code: Space, keyCode: 10 ('Space')
> | Resolving ctrl+shift+[Space]
> \ From 21 keybinding entries, matched chord, when: no when condition, source: user.
> + Ignoring single modifier ctrl due to it being pressed together with other keys.
> / Received keydown event - modifiers: [], code: KeyS, keyCode: 83, key: s
> | Converted keydown event - modifiers: [], code: KeyS, keyCode: 49 ('S')
> | Resolving [KeyS] chorded from ctrl+shift+[Space]
> \ From 1 keybinding entries, matched workbench.action.files.saveFiles, when: no when condition, source: user.
NOTE: "I removed the timestamps from the beggening of the lines to make them shorter."
The issue might be due to some other extension. In my case, this issue was resolved by removing the "Dependency Analytics" extension. Due to this extension, *.ipynb files were picking CVE as cell language mode. I wasn't able to change the cell language mode to Python without removing the extension. Upon removing, the extension, *.ipynb files showed Python as cell language mode and this resolved issues with key bindings as well as with syntax highlighting.
Note: Cell language is the small text that comes on the bottom right of each cell in a ipynb file. This should be Python for key bindings and syntax highlighting to work properly.
In sublime text I used to use a shortcut that allowed me to tab through my multi selection and edit each element individually.
for example I would cmd+d a word then the shortcut would allow me to tab through each selection and edit them individually.
I haven't used sublime text in a month since I switched and can't even remember the shortcut I used to find the name of that action. so I don't even know if it was a plugin or a built in short cut.
is there a similar shortcut in vscode?
You can multi-select in VSCode using alt+click
(can be changed to cmd+click in "Selection -> Switch to Cmd+Click for Multi-Cursor").
To tab through your selections install the tab-through-selections extension and then use cmd+shift+u to start iterating (alternativley ctrl in Windows), then:
tab to go to the next selection
shift+tab to go to the previous selection
click anywhere to cancel iterating
Hope this helps :)
When I attempt to save my file on Visual Studio Code with the cmd+s keyboard shortcut, it does not save the code. I have to manually click File, the Save, just to be able to save my progress. I'm using macOS Catalina version 10.15.7 and VC Code version 1.55.2.
How do I fix this?
Attempts:
-Checked if ⌘ Cmd + S keyboard shortcut is tied to the Save functionality
If you do it right this solution will fix your issue.
I have never had a problem saving with VS-Code personally, but I have had issues with keybindings. IDK if you write your own keybindings, but if you do, you might want to check the keybindings that you have wrote to make sure they do not conflict with [CTRL + S]. The keybindings.json file that you create custom keybindings in, overrides the default keybindings.json file that defines the keybindings that VS-Code ships with.
To check your keybindings.json file...
Hit the F1-Key
A menu will drop open type in "Keyboard Shortcuts"
There will be two Preferences: Keyboard Shortcuts
Make sure to select Preferences: Keyboard Shortcuts and not Preferences: Default Keyboard Shortcuts
If the file is empty you are good. If you have keybindings written in the file, you need to iterate through them by hand, checking each one. Make sure that none use [CTRL + S] together. Even if the keybinding uses [CTRL + S] and other keys, you will need to disable it, so you can test if it is causing an issue.
Debugging [CTRL + S]
If your keybindings.json file is all good, then great, that's one thing to scratch off the list. The only thing left to do now is debug the Bound Key ("Key Binding"). To debug keybindings, you will use a built in tool, that VS-Code offers. To start do the following:
Hit the F1-Key
When the quick input drops open type the following into the text input:
"Toggle Keyboard Shortcuts Troubleshooting"
Select the option: Developer: Toggle Keyboard Shortcuts Troubleshooting
It should automatically open the OUTPUT panel, which is located in the same panel that your terminal is. Make sure that the OUTPUT is set to LOG(Window) in the drop down. (I took a picture and posted it below if you can't find the Keyboard Shortcut Troubleshooter).
The image might have funny declensions because I am on a dual monitor setup with 1 1080x1920 curved screen and one 1080x720 screen.... I cropped it to a STD HD 1920 width.
I Got My Trouble-shooter working, and Output open, now What Jay?
Okay... Well your at the right spot. Now every-time you press some keys, you should see your OUTPUT WINDOW working like crazy. It should be logging all sorts of stuff, which is good, very good.
This Part Is Important! READ CAREFULLY
What you want to do is use your keybinding that you feel isn't working appropriately. Use it when focus is set on an editor, use it when focus is set on a different editor, use it when focus is set on the sidebar. Where you are focused at in the editor at any given time can greatly affect a keybinding. The output is gonna write lines every-time you use your keybinding. Try not to hit any other keys while doing this, so you have a column in you output that includes logging from the keybinding you are testing only. Read the output see what it says. See if it looks right, or wrong. If it looks wrong, you can visit this link, to the VSCode site that covers this topic, and see if you can fix it your self. If you can't fix it your self, come back here, and edit your question. When you edit your question make sure that it includes the Troubleshooter's Logging Output.
VSCode Troubleshooting Keybindings (Keyboard Shortcuts) # https://code.visualstudio.com/docs/getstarted/keybindings#_troubleshooting-keybindings
Image that shows how to open the Keyboard Debugger
Also shows how to set the OUTPUT to Log(Window)
StackOverflow-2021-JUNE-26018:34-PST
Another thing to check for is, for lack of a better term, combination key bindings. For example, I was having an issue with ⌘+s. VSCode gave a message that it was waiting for the second key binding. After looking at the keybindings.json, I noticed I had a key binding for opening up user snippets as
{
"key": "cmd+s cmd+n",
"command": "workbench.action.openSnippets"
}
The ⌘+s portion of this key binding conflicted with the default ⌘+s
In sublime text I used to use a shortcut that allowed me to tab through my multi selection and edit each element individually.
for example I would cmd+d a word then the shortcut would allow me to tab through each selection and edit them individually.
I haven't used sublime text in a month since I switched and can't even remember the shortcut I used to find the name of that action. so I don't even know if it was a plugin or a built in short cut.
is there a similar shortcut in vscode?
You can multi-select in VSCode using alt+click
(can be changed to cmd+click in "Selection -> Switch to Cmd+Click for Multi-Cursor").
To tab through your selections install the tab-through-selections extension and then use cmd+shift+u to start iterating (alternativley ctrl in Windows), then:
tab to go to the next selection
shift+tab to go to the previous selection
click anywhere to cancel iterating
Hope this helps :)
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!