How to send a file to VS Code from anywhere
You have a file somewhere, and you want it open in VS Code. Maybe it is a config file a teammate sent you in Slack, a log you just downloaded, or a script sitting in a folder three levels deep. The editor is open and waiting. The only question is how to get the file into it with the fewest detours, and the Mac gives you several answers that are each right in different situations.
The ways VS Code already accepts a file
VS Code is generous about how it takes a file, which is good news once you know the options.
- Drag the file from Finder onto the editor’s icon in the Dock, and it opens there.
- Drag the file straight into an open editor window, dropping it on the editor area, and it opens as a tab.
- Drag it onto the file explorer sidebar inside a project, and it opens in place within that workspace.
- Use File, then Open, and pick the file from the standard dialog.
Each of these works. The one you reach for usually depends on where the file is and whether the editor window is already visible. If VS Code is buried behind other windows, the Dock icon is easiest. If a project is open and you can see the sidebar, dropping it there keeps it in context.
The command-line route
If you have installed the “code” command, the terminal is often the fastest path of all. From any folder you can type code followed by a filename to open that file, or code and a dot to open the whole current folder as a workspace. This is why so much of the friction around VS Code comes down to one thing: getting the file’s path into a terminal.
You can copy a path in Finder by selecting the file and pressing Option-Command-C, which puts the full path on the clipboard. Then you switch to the terminal, type code, paste, and press Return. It is reliable, but it is four steps, and the copy-as-pathname shortcut is one many people never learn.
Where it gets tangled
The trouble is rarely a single file. It is the collecting.
Say the file you want came in a chat, and two more you need are in Downloads, and a fourth is in a project folder you have open in Finder. To get all four into VS Code you make four separate trips, each with its own aiming and dropping, and if the editor window is behind other windows you rearrange the screen every time. Drag and drop also insists you hold the file for the whole journey, so there is no pausing halfway to find the next one.
The command-line route has its own snag: it wants a path, and most of the places a file comes from hand you the file itself, not its path. A file dragged out of a chat is not a path. A file in Finder is not a path until you deliberately copy it as one. So you end up translating between “the file” and “the path to the file” by hand, over and over.
A shelf between the file and the editor
This is the gap Ledge is built for. Drag each file up toward the notch at the top of the screen and drop it on the shelf that drops down. Gather all four there: the one from the chat, the two from Downloads, the one from the project folder. Now they are in a single spot, and you have stopped holding any of them.
The useful part is what the shelf does on the way out. Drag a file off it onto a VS Code window and the file opens as a tab, the same as a normal drop. But drag that same file onto a terminal instead, and Ledge pastes the path as text, ready for you to prefix with code and run. One file, two destinations, and each gets what it can use: the editor gets the file, the terminal gets the path. That is exactly the translation you were doing by hand, done for you.
Because the shelf sits at the top of the screen and stays put, the editor and the terminal do not both need to be visible at once. You pull a file down to whichever is in front of you. The apps you route to most, including your editor and terminal, are ones you choose in Settings so they stay available on the shelf even when they are closed.
Picking the right method
There is no single best way to open a file in VS Code, only the right one for the moment.
- One visible file and an open window: drag it straight in.
- A file whose path you need on the command line: copy it as a pathname, or pull it off the shelf onto a terminal to get the path without the extra steps.
- Several files from several places: stage them on the shelf first, then send each to the editor or the terminal as needed, rather than making a separate trip for every one.
Everything stays on your Mac; the shelf never uploads a file to move it, and there is no account involved. It opens with a keyboard shortcut or a click on the notch, and on a Mac without a notch it appears at the top centre of the screen. What you are really removing is the step in the middle, the one where you keep having to decide whether the destination wants the file or its path, and then produce whichever it was.