In VSCode, is there a command to navigate from a diff view to the local file
Asked Answered
S

4

11

Let's say I've clicked on a file in the Git changes view and it opened a diff. I realize I can (usually) edit that file on the right side of the diff.

Is there a command that will open the right hand (local) file in it's own editor, as if I had clicked on it in the Explorer?

Smoko answered 2/2, 2021 at 17:41 Comment(0)
C
9

The command is git.openFile. You can add a custom keybinding, for example to f4:

    {
        "key": "f4",
        "command": "git.openFile",
        "when": "isInDiffEditor"
    }
Camber answered 2/10, 2022 at 21:36 Comment(0)
T
4

Do you consider the Open File icon to the right of the file name a command? I'm not familiar with any other way to do it.

enter image description here

Tetany answered 2/2, 2021 at 17:48 Comment(3)
Thanks, I didn't see that icon in the Tab strip... for reference, that is not the general Open File command, but the git.openFile command. Also, while I was waiting I also found a half answer in that using the Reveal Active File In SideBar command places the keyboard focus on the file in the Explorer and then you can hit Enter.Smoko
What's the difference between the general versus git open file command?Tetany
workbench.action.files.openFile (usually mapped to Ctrl + O) opens the Open File dialog so that you can select a file from your hard drive. git.openFile navigates from a diff to the file (not in the diff mode)Smoko
D
1

It appears what you want is the new command workbench.action.compareEditor.openSide currently in the Insiders' Build v1.74.

If the right-hand side of the diff has focus then triggering that command will close the diff and open the right-hand side in its editor. And similarly if the left-hand side had focus.

Dilan answered 13/12, 2022 at 4:12 Comment(1)
I wonder if there are cases that this command handles and git.openFile doesn't 🤔Repp
A
0

In my case I had set workbench.editor.editorActionsLocation settings to 'hidden'. Reverted it to the default fixed it.

"workbench.editor.editorActionsLocation": "default"

These were hidden

Auriferous answered 29/5, 2024 at 20:32 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.