OS X: cycle between windows in visual studio code - visual-studio-code

I'm trying desperately to figure out how to cycle through windows in Visual studio code. In Finder, there is a menu item Cycle Through Windows which I use frequently. However, this seems to be a Finder option. So I looked through the global shortcuts (since the requirement is probably the same for many applications) and assigned the Move focus to next window to shift-cmd-F1. This works in Finder and Text Editor, but not in Visual Studio Code. I checked if the key binding is overridden in VSC but I don't think so.
Has anyone got this figured out and can help me?
edit: just found that this is a global shortcut under System Settings > Keyboard > Shortcuts > Move focus to the next window. Unfortunately, Visual Code doesn't use it.

I added the following shortcut to keybindings.json
{
"key": "alt+tab",
"command": "workbench.action.quickSwitchWindow"
}
workbench.action.quickSwitchWindow does exactly what I want and it has no default shortcut enabled (on a spanish keyboard at least).

So, finally found the solution: Though for some reason the system-wide shortcut for Move focus to next window does not work, there is another shortcut which does: shift+cmd+~ :)
Found it here: https://support.apple.com/en-us/HT201236

command ⌘ + ` is working nicely for me on macbook Pro.

You can use Switch window from command palette (command: workbench.action.switchWindow). The default shortcut is Ctrl + w.
It lists all the open windows for you to select and go.
It's improved further.

The newest version of Visual Code (1.55.2) has window switching enabled by default.
The hot key is Control+W (⌃+W), which will bring down a command window for you to select which window to jump to.

shift ⇧ + command ⌘ + ~ works for me unless I am in full screen mode. Alternatively, you can use the following shortcuts in full screen:
shift ⇧ + command ⌘ + p then type "Switch Window".

There seem to be tons of ways to cycle windows. I finally found one that worked for me:
shift + cmd + "{" or "}"
If you go to "window" in the application you'll see menu items for "Next Document" and "Previous Document".

Just FYI, the shortcut for Ubuntu(Gnome 3) is alt + ` for switch between visual studio code (or other applications) windows.

Personally, I rather use quickOpenRecent instead of quickSwitchWindow because it allows me to quickly switch between the last used window and the current one (stacked cycling instead of sequential). I have the following mapped to alt+tab:
{
"key": "alt+tab",
"command": "workbench.action.quickOpenRecent",
"when": "!inRecentFilesPicker"
},
{
"key": "alt+tab",
"command": "workbench.action.quickOpenNavigateNextInRecentFilesPicker",
"when": "inQuickOpen && inRecentFilesPicker"
},
{
"key": "shift+alt+tab",
"command": "workbench.action.quickOpenNavigatePreviousInRecentFilesPicker",
"when": "inQuickOpen && inRecentFilesPicker"
}

Set the Quick Switch Window... keyboard shortcut to command+N
is a better work around for me.
Go to the menu Code/Preferences/Keybord Shortcuts and search for quickSwitchWindow

To cycle through windows that are in the same desktop, I use :
shift + command + `
Mac OS 12.2. Azerty, and VS Code 1.64.2

None of cmd+` cmd+shift+F1 or shift+cmd+~ work for me but ctrl+cmd+\ does.
I'm using a UK Windows keyboard layout - not sure if that affected it..
Edit: I originally found that cmd+\ was working but having restarted VS Code that changed to ctrl+cmd+\ - very odd

if you know how to open keybodard shortcuts from vscode,
type "switch" in input box which has a placeholder "Type to search in Keybindings". you will see "switch window...".
i am using macbook and ^ + W is an default shortcut key for switching windows in between.

I'm running macOS Monterey, control^ + w worked for me.

in VsCode press Ctrl+Shift+P and search Open next editor and click on Setting button and change it to your shortcut keys!

Related

How to come back to single cursor mode in Visual Studio Code

In Visual Studio it is possible to place the cursor on multiple lines in order to edit them in parallel. On my OS (Ubuntu), the shortcut to enable the multi-cursors mode is Ctrl + Shift + Up or
Ctrl + Shift + Down.
Is there a shortcut to come back to the single-cursor mode?
On the official documentation there is nothing on this feature, neither for activation, nor for deactivation. In order to make this question as more general as possible, since Visual Code's shortcuts are OS-dependent, I'm looking for an answer covering all the major OS.
I am not on linux, but it should be escape, which is bound to Command workbench.action.terminal.clearSelection.
You can check this in Keymap Shortcuts
{
"key": "escape",
"command": "workbench.action.terminal.clearSelection",
"when": "terminalFocus && terminalTextSelected && !terminalFindWidgetVisible"
}
I answer my own question.
Apparently, in the current version of Visual Code, it is sufficient to press Esc to come back to the single cursor mode.
In Windows pressing ALT key twice will work fine, I hope pressing Option key twice will work in Mac OS. Thank You! :)

How I can make `ctrl + click` to go to definition in visual studio code editor for mac OS?

How I can make ctrl + click to go to definition in visual studio code editor for mac OS? Now it is F12 which is using my mac for show desktop.
First and foremost, please note that in VS Code for macOS, the familiar Ctrl + click from Windows / Linux operating systems has been replaced with ⌘ + click (i.e.: "command + click"). Try that first before proceeding any further as that shortcut should work out of the box without any special modifications.
However, if the above still doesn't work for you then try fixing the problem by editing your settings.json file. To do that, press F1, type settings json, then click Open Settings (JSON), and then do one of the following:
To use ⌘ + click as your "Go to definition" shortcut, ensure the following line exists in your JSON settings:
"editor.multiCursorModifier": "alt",
What this does is it explicitly sets VS Code's "add another cursor" shortcut to option + click (try it out for yourself!), thus freeing up ⌘ + click to be used for the "Go to definition" operation.
Conversely, to use option + click as your "Go to definition" shortcut instead, add:
"editor.multiCursorModifier": "ctrlCmd",
Note: the above line will actually set the "add another cursor" shortcut to ⌘ + click (not Ctrl + ⌘ + click, as implied by the JSON value).
Settings > User > multiCursorModifier must be set to alt (default), so the ctrl/cmd will be available to go to definition.
Documentation:
The modifier to be used to add multiple cursors with the mouse. The Go To Definition and Open Link mouse gestures will adapt such that they do not conflict with the multicursor modifier.
In gear icon/keyboard shortcuts, search for f12 .
Right-click on the "Go to Definition" entry and chose "Remove Keybinding".
Note that will put a new entry at the end of your keybindings.json like:
{
"key": "f12",
"command": "-editor.action.goToDeclaration",
"when": "editorHasDefinitionProvider && editorTextFocus && !isInEmbeddedEditor"
}
Note the "-" sign before the command, that removes that keybinding.
Now copy and paste that whole entry below it (with a comma at the end of the previous entry):
{
"key": "f12",
"command": "-editor.action.goToDeclaration",
"when": "editorHasDefinitionProvider && editorTextFocus && !isInEmbeddedEditor"
},
{
"key": "cmd+enter",
"command": "editor.action.goToDeclaration",
"when": "editorHasDefinitionProvider && editorTextFocus && !isInEmbeddedEditor"
}
Remove the minus sign and assign whatever keybinding you like. Alternatively, go back to shortcuts file, search for "Go to Definiton" and click the pencil icon to use its interface to create a new keybinding.
Note that Ctrl-Enter is used in many contexts so you might have an unexpected conflict using such a common keybinding.
In my case, I checked this in the settings
Settings > User > multiCursorModifier must be set to alt (default)
By default, it is set to alt only
I just did right-click on VS code and quit and open it again to resolve the issue.
Hope it may help someone!
I was facing similar issue with my python code though it was working fine with my JS code. I have to install Python extension developed by Microsoft & it worked.
In my case cmd+click wasn't working when i was connected to a remote machine via remote ssh, but worked fine locally. Installing language extensions(C/C++ Extension Pack in my case) on a remote solved the issue for me.
go to .flowconfig file and change the required the version(it is the bottom)
I found what turned off this feature.
Go to Settings and search for "ctrlCmd". There are two settings that overrode the command: Editor: Multi Cursor Modifier and List: Multi Select Modifier. I turned both of these off because I don't use them, and I got my control-click to definition back.
I know those settings are useful to some. The default for both is alt-click. I presume an extension or an update changed something.
For me Ctrl ^+click / Cmd ⌘+click was not working, although F12 was. So, tried with option ⌥+click, which worked.
In my vscode, this problem is proved to be caused by some extensions. After removing one extension(I forget the name, should be related with vscode), it works.

Ubuntu Visual Studio Code Toggle Comment no respond

I encountered an issue with toggle comment in visual studio code on Ubuntu. Default hot key was "ctrl+/", it didn't respond when I click on a line of code or highlighted the line of code. I changed the hot key to "ctrl+l" under preference -> Keyboard Shortcuts and it didn't respond too.
I tried to google this but nobody seems to encounter this issue or posted this question.
Is there something else I need to enable to make this work?
In my case it was due to the fact that VS Code 'didn't know' the language the file was written in. I was editing a .cmake file and VS Code does not 'understand' CMake syntax when installed out-of-the-box.
Installing a 'CMake' extension enabling CMake syntax highlight also enabled the 'Toggle Line Comment' [Ctrl+/] shortcut to work.
(I'm guessing without the specified language VS Code simply does not know which symbol to use to comment out the lines - e.g. '//' or '#' or else).
This the issue because in ctrl + /
/ -> is numpad divide
or
/-> simple / the key not present in numpad
so if you try any of these combinations one will definitely work, if u want to work with numpad one only you can go to
File-> Preferences -> Keyboard shortcuts (there search for toggle line comment and give your own shortcut)
For me, in VSCode has a error with ctrl + } and ctrl + shift + } 'cause is inversly and no show correctly the keys to hit.
You must redirect to Keyboard Shortcuts - Visual Studio Code, and search the shortcut "Comment", and hit:
blockComment: Insert ctrl + } when you hit ctrl + shift + }.
commentLine: Insert ctrl + shift + } when you hit ctrl + }.
The Shortcuts show like this
I hope that help for you.
That how I solved it. Open File/Preferences/Keyboard Shortcuts or type ctrl+K ctrl+S VSCode preferences. Then click {} button in the top-right corner. In the last version on Sep 16, 2019, it looks like a file with the arrow. Now you see keybindings.json, at the bottom there is a button Define keybindings - click and type in the form there "Ctrl+/" It will show you all commands with your combination. I found and commented the one from Emmet
` {
"key": "ctrl+/",
"command": "editor.emmet.action.toggleComment",
"when": "editorTextFocus && !editorReadonly"
},`
There was a conflict.
I had the same problem and I didn' found the answer in the internet, but eventually I found it on my own.
My system is Linux Mint and my computer is a Thinkpad 440p with an brazilian Portuguese keyboard. This keyboard doesn't have a Right Control key, and then key usually associated with it is used for slash (/) and interrogation mark if pressed with shift. Mint has a good driver for it, mapping it to the correct symbol. I have never had issue with any other code editor or software.
However VSCode by default bypass this keymap done by the system and uses raw code com from keyboard hardware. This can be changed in setting, keyboard dispatch. I change it from "code" to "keymap" and then it worked like a charm.

Refresh Visual Studio Code list of files

Visual Studio Code (Version 0.10.11, on OSX) does not refresh the files in a folder. Is there any way to force it to refresh. Currently I have to close and reopen the whole program.
EDIT: In the meanwhile a reload button has been added to the file explorer widget.
Use the workbench.action.reloadWindow command.
Go to File -> Preferences -> Keyboard Shotcuts and define a shortcut for this command. On my system it's placed on Ctrl+F5. The entry in keybindings.json looks like this:
{
"key": "ctrl+f5",
"command": "workbench.action.reloadWindow",
"when": "editorTextFocus"
}
If you hover over the workspace root in the navigator, four icons appear to the right of it. The third of those icons, a circular arrow, is Refresh -- it reloads the file list.
You can use the command palette to reload the window:
Open the command palette with View > Command Palette... (or Shift+Cmd+P on OS X)
Type reload window and press enter
You shouldn't need to reload the entire window, just the folder list. Reloading the window will kill terminals, lose undo history, etc. You can do this using the refresh button in the explorer (second from the right):
If you find you need to do this a lot you can add a keybinding for it, for example:
{
"key": "ctrl+f5",
"command": "workbench.files.action.refreshFilesExplorer"
}
Ran across this today with VS Code 1.13.0 and in Keyboard Shortcuts I see
workbench.files.action.refreshFilesExplorer
To reload a single file:
⇧⌘P
type "Revert File"
On Windows:
Ctrl + Shift + P
type "Revert File"
Tested in VSCode v1.18.1 on Windows
If you use the SFTP extension you can do this for refreshing the SFTP:EXPLORER list (tested on Windows with VSC 1.40.2):
File => Preferences => Keyboard Shortcuts => Search for: refresh
Then you have to find "Refresh / sftp.remoteExplorer.refresh" in the result list.
Click the entry, then click the plus sign before the entry, then press your desired shortcut and hit "enter". I took "Ctrl + Alt + F5" because this has not been used for other commands already.
Right-Click your sln (Will say 0/n solutions)
In the bottom row of dialog it will say reload project solutions.
If it's not present, then it was just reloaded most likely. Try to run build again.
When search.maintainFileSearchCache option is enabled I started to find the files with I'm using Ctrl-P shortcut
"Ctrl + Alt + R" on v 1.27.1 as of 9/11/18

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!