Is there a VS Code shortcut to open active file in another tab? - visual-studio-code

All I've been able to find is cmd + K O, which opens the active file in another window. Searching for a keyboard shortcut to open the active file in a new tab in a split window.
I want to start with one tab open with index.js, and end up with two tabs, each with index.js, ideally in a split window.

The keybinding command IDs you are looking for are the ones that start with the prefix workbench.action.splitEditor. You can open your keyboard settings file with the Preferences: Open Keyboard Shortcuts (JSON) command, or open the keyboard shortcut editor GUI with the Preferences: Open Keyboard Shortcuts command.
To learn more about how to customize keybindings, see https://code.visualstudio.com/docs/getstarted/keybindings.

Related

Vscode open a file without dialog

Is there a way to quickly open a specific file (Console.R as a example) by a keyboard without the appearance of a dialog (like Ctrl + o or Ctrl + p, which pop up a dialog to select which file)?
I have a specific file and just want to open it quickly. For R language terminal is lack of many useful characteristics (like auto-completion and syntax highlighting), I want to allocate a specific file (like Console.R) as the input of R terminal but I don't find a way to open a specific file quickly.
Sorry, this is duplicated with Keybinding to open a specific file in vscode and vscode keyboard shortcuts to specific files.

VS Code open file in new tab hotkey

I want to navigate VS Code with only the keyboard. I want to select a file in the explorer, then use a hotkey to open in new tab.
Space and Enter replace the existing tab. This because I have preview mode enabled. I often do want to replace the current tab instead of opening a new one. I want to be able to choose between opening in a new tab and replacing the current tab by hotkey.
Control + Enter opens a file in a new column. Often I want to open the file in an existing column, but a new tab. How do I do that with explorer-friendly hotkeys?
To open a selected file in a new tab you can do ctrl+K O(first press ctrl+k then press O).You can do ctrl+K ctrl+S to open Keyboard Shortcuts. Some of them does not have keyboard shortcuts by default. In there you can assign your keyboard shortcut for the action you desire.

Keyboard shortcut to switch from source control "diff" mode back into normal editing?

When I select a file from the source control panel (in my instance I'm using git), it then opens the side-by-side changes for that file.
I'm aware you can edit the file on the right hand side, but is there a quick way to close the open tab and open the original file itself? Preferably a keyboard shortcut.
The shortcut I'm presenting as a solution is slightly long but will work for sure.
As soon as you open the file from the source control panel use the following shortcuts to copy the file's relative path
Windows/Linux ctrl+k Mac cmd+k immediately followed by ctrl+shift+c \ cmd+shift+c
This will copy the relative path of the file
you can then use the command ctrl+f4 / cmd+f4 to close the opened history view of the file
then open the command palette using ctrl+shift+p / cmd+shift+p and remove the > character and paste the relative path of the file using ctrl+v / cmd+v
When you open the file in the diff view take care not to click the cursor within the editor as this will move to editor focus. When in editor focus the command to copy the relative path will not work. However this can be fixed by changing this in the keyboard shortcut settings.

Is there a shortcut to close source tabs in the devtools debugger?

As pictured here, I'm wondering if there is a keyboard shortcut to close these tabs either one by one or in bulk
AltW or OptW (Mac) to close the active tab. See Sources panel keyboard shortcuts.
CtrlShiftP or ⌘ShiftP then type clo and it'll show you "Close All" command.
Right-click a tab name > select Close all.

Open current editing file in explorer tree

I'm wondering if there is a shortcut for VS Code that highlights in solution explorer tree current opened file. Like we have in Visual Studio:
Alt + Shift + L
Couldn't live with no complete answer, so figured out the following:
Without a direct keyboard shortcut:
Open the command palette via Cmd-Shift-P (or Cmd+P then >) and type Files: Reveal Active File in Side Bar.
This reveals the active file in the side bar similar to Visual Studio's Alt+Shift+L
Then, take the above and map a keyboard shortcut to it:
Open keyboard shortcut preferences file via Cmd-Shift-P followed by Preferences: Open Keyboard Preferences File.
Add in the following (taking Visual Studio's lead, I've personally mapped it to Alt+Shift+L, but map to what you want).
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "shift+alt+l",
"command": "workbench.files.action.showActiveFileInExplorer",
},
]
Note that it's not as good as Visual Studio, Atom, etc. in that you can't then navigate with arrow keys in the tree (arrow keys navigate the active file contents), but I guess I'll eventually figure out how to do that.
#Tomoyuki Aota points out that you can do the following to navigate with arrow keys:
After Files: Reveal Active File in Side Bar, press Ctrl+Shift+E (Show
Explorer). After that, I can navigate the files in the explorer by the
arrow keys.
I don't think there's a command for that, but there is a shortcut to enable/disable revealing the current file as you open it:
"explorer.autoReveal": true
Try this:
Together with #Rob's correct answer:
"explorer.autoReveal": true
then Ctrl-Shift-E (Show explorer) focuses that file in the explorer and the arrow keys will navigate up/down/left/right like any list. This works even if the explorer is closed prior to the Ctrl-Shift-E.
Ctrl-Shift-E has the added bonus in that it will toggle focus between the highlighted file and its editor as well.
For mac, use Cmd-Shift-E
Right-click the file tab (not necessarily current one) and click "Reveal in Side Bar".
I was able to achieve this by customizing the workbench.files.action.focusFilesExplorer command with keybinding Alt + shift + L
Open the Keyboard Shortcuts ctrl + K + shift + S
search for focusFilesExplorer command & customize
Provide your keybindings that you are used to - I set mine to Alt + Shift + L
F1 then type "reveal" also works from in VS Code, at least for me.
It looks like the actual version of VS Code offers a command for this feature now.
In the settings, type revealInExplorer in the search bar to find the command. There is no default keybinding, so just put your own. Works like a charm!
Download the open in browser extension, that's it.
Right click > Open in primary/secondary browser function appears, and the ALT+B / ALT+SHIFT+B shortcuts become available.
Had a similar case and ended up here looking for help.
I opened a file in "preview" mode after clicking a link in a .md file and wanted to know where this opened file was located in the project.
I found this button in the upper right corner of VS Code which was exactly what I wanted:
It's called "show source"
Also check "Explorer: Auto Reveal Exclude" patterns in VS Code settings. Files that fit any of the patterns will not be auto revealed in the Explorer tree.