Is it possible to paste files copied to the clipboard from other applications in VS Code? - visual-studio-code

Within the explorer panel of VS Code itself, if I want to copy a file to another directory in the workspace, I can use ctrl+c and ctrl+v, but if I find a file from another application on my computer such as the native File Explorer application, first pressing the shortcut key ctrl+c and then going to the VS Code window and pressing the shortcut key ctrl+v in the Explorer panel, there is no effect.
Note that I'm not talking about copying the contents of the file and pasting into VS Code. I'm talking about copying "the file" as in the notion of the file to the desktop environment.
The workaround is the use the native file explorer, copy the file first, then open the folder opened in VS Code, and finally paste it within the native file explorer. But I find this so troublesome.
Is there an easier way to do this? Does VS Code support such functionality to paste files copied to the clipboard from a different application (not VS Code) and paste into VS Code? Is that functionality hidden behind a setting that I need to change? Or is this possible via an extension?

Vscode does dragging the filename from a native file explorer (at least on Windows) and dropping in vscode's Explorer where you want it.
You can also use your OS's Open With... functionality and then drag the tab of that editor into whichever directory you want.

You can choose Add File from File to add a file to your workspace. Or you can use New File from File to create a new file in your workspace and copy the content of the file outside to it.

At the time of this writing, this is not supported... yet!
Work to implement this is tracked under this GitHub issue: Explorer: allow to paste files from the clipboard into target folder #130036, which is a subtask of a larger issue tracking a larger effort for Better drag and drop / clipboard integration of files across applications #164.
You can give a thumbs up reaction on those issue pages to increase their prioritization (but please don't leave "me too" comments there, as such comments are considered annoying noise).
pingren (a contributor to the VS Code repository) tried to implement this and found it to be more complicated than it looks. You can read their explanation of why in their comment there. One of the difficulties stems from itegration with system keybindings and VS Code's affordance for remapping keys:
the onPaste event could only be triggered by system paste (cmd+V on macOS). Users could change filesExplorer.paste command to any keybindings. So we need to consider how to merge native paste from clipboard and VSCode explorer paste.
There's another feature-request issue (Copy paste files from native explorer to vscode #89862, created before #130036) where isidorn (another VS Code contributor) commented:
This is a fair feature request however I believe there is a Chrome limtation which is preventing us from achieving this. [...]
As for extensions that might do this, I don't know of any (but haven't tried searching intently).
Other possible workarounds:
Try dragging the file from your native file explorer application to the VS Code file explorer panel. This is confirmed to work at least on Windows and Ubuntu.
From Mark's answer (copied under CC-BY-SA):
You can also use your OS's Open With... functionality and then drag the tab of that editor into whichever directory you want.
From user103's answer (copied under CC-BY-SA), and partially mentioned in the question post already:
You can choose Add File from File to add a file to your workspace. Or you can use New File from File to create a new file in your workspace and copy the content of the file outside to it.

Related

How to prevent VS Code remembering files outside work folder?

My workflow with VS Code is to always use project folders on projects. This works great, but there's one thing that's messing things up right now;
When opening just a single file from another project while working in another project, lets's say webpack.config.js, I use Windows Explorer rightclick to open that file in VS Code. However, this always opens the file in the currently open VS Code instance.
This adds the file from that other folder now to the memory of the previously opened files in the open project while it has nothing to do with that project.
When using the quick file open of VS Code now it happens a lot VS Code opens a file from that other folder, only because that outside file has been opened once while I was working on this project.
This is error prone as now it happens a lot, especially when working fast, that the wrong, for instance, package.json or webpack.config.js file gets opened, because VS Code now also suggests files that are outside this project. That's pretty frustrating and causes changes to be made in the wrong files pretty quickly.
I know we can clear the editor history and have to do it a lot now. But to me that's the other way around, doesn't solve the real problem and when not done often the issue remains.
So I want to get rid of this issue and have the following questions:
1) How can we change the 'Open with Code' rightclick menuitem in Explorer to open files always in a new instance of VS Code?
2) Is there a config settings to disable the behaviour that VS Code remembers files that are outside of the current work folder?
Thanks in advance, this thing is bothering me for quite some time now!
How can we change the 'Open with Code' rightclick menuitem in Explorer to open files always in a new instance of VS Code?
I assume you are a Windows user. You can edit the context menu behavior from Regedit.
Follow the below steps:
Press Windows + R
Type regedit and press OK
Go to Computer\HKEY_CLASSES_ROOT\*\shell\VSCode\command in regedit
Add -n parameter to the command like below
It will help you to open every file in a new window when you use Open with Code.
For your second question, Is there a config settings to disable the behavior that VS Code remembers files that are outside of the current work folder?
Open VS Code settings
Search window.openFilesInNewWindow
Make it off to on like below
With this configuration, you can't open new files in the current workspace therefore technically you prevent VS Code remember outside files. Not directly but it helps.
I don't like how "recently opened" files are shown in VS Code Quick Open (Ctrl+P). I think OP is describing this behavior...
The behavior to remember "recently opened" files causes me problems when I mistakenly open a temporary/copy of my file, i.e.
C:/users/temp/code.js
... instead of the true file (i.e. located inside the currently-open VS Code project)
C:/git/source-control/code.js
...my confusion happens because because both files are listed among the options when I use Quick Open Ctrl+P and type "code"
For me , the Quick Open list also has the answer, any "recently-open" files should have an "X" icon on the right side. You may need to hover your mouse over the file you want to remove.
Click the "X" icon to "Remove from recently open". Quick Open will always be able to find files in your current project, even if you remove them from recently-open:
Please note I don't have access to regedit as suggested in the accepted answer; my answer here does not require regedit

VS Code does not see existing file

Apparently VS Code does not list existing files in files dropdown (Ctrl + P command).
Here is what it shows:
As you can see, the file laravel-2019-09-26.log exists in the directory (left bottom), but not in the files dropdown. After I open this file from the Explorer tree, it starts showing in the dropdown.
Am I doing something wrong or does this happen for everyone? Or is this command supposed to show previously opened files only? If so, what is the way to quickly open any existing file in the workspace?
N.B: I have gone through this related question. No one has mentioned this problem, making me think that this might be specific to my machine.
Edit
For future readers, second answer provided by #michaelze is spot on. VS Code by default does not list files mentioned in .gitignore. You can change this setting by going to Settings panel (File > Preferences > Settings) and typing useIgnoreFiles. This will bring up two boolean settings named Use Global Ignore Files and Use Ignore Files. Turn off these two settings and all workspace files will start showing in the files dropdown. Works correctly as of version 1.38.1.
As those files are .log files, I assume, they are maybe mentioned in the .gitignore file? Maybe this can help you? Visual Studio Code - Automatic exclude based on .gitignore
The list you are seing when pressing CTRL + P is called recently opened. When you open one of the files, it was recently open, so it shows up. The CTRL + P menu also has a files results section that lists actual search results from the files you have in your workspace. None of your .log files are showing up in this section (hence the section is not visible).
The laravel-2019-09-08.log file is also missing from the drop down.
I was wondering if maybe the listing is capped to a certain number of files. Try to be more specific with your search. In my version of VSCode, I can search for files using multiple words. Maybe try searching for "laravel 26" to find the file you are looking for?

New file shortcut in file explorer does not work anymore

I just updated from 1.34.0 to 1.36.1 and somehow I am not able to create new files with my keyboard shortcut in the file explorer.
I used to just press "a" in the file explorer to create a new file (and shift+A for a folder) and now it instead starts to filter files (see the picture below where I pressed "aaaaaaaaaaaaaaaa" to show what I mean by "filtering files").
I am not working with a lot of files and already using the CTRL+E menu to search for files, where can I disable this feature or at least get my "new file/folder" shortcut working again ?
Found the solution here, as of vscode 1.36.1 the accepted answer is still valid:
https://superuser.com/questions/1417361/how-to-disable-file-filtering-in-vs-code-sidebar-explorer

VSCode: Any possibility to have a second, workspace-independent file explorer in the side panel?

I am looking for a way to open files in vscode that do not belong to the currently active workspace (and should not belong to it, this is not about multi-root-workspaces).
The ideal solution I could imagine would be a second explorer-panel that allows to browse the whole filesystem-tree and open files from it just like the built in explorer.
Is there maybe an extension for that I haven't found yet?

Can you create a file or folder by path in VS Code?

In Atom, hitting Cmd+N brings up a window where you can type in basically any path to create any file or folder anywhere in the project. In VSCode, hitting Cmd+N brings up a dialog where you can create a file in the currently focused folder, and I believe you can type a path to create a file in a subfolder (whether it exists or not), but not as flexibly as in Atom.
Is there way to do it Atom-style in VSCode?
I don't know for sure whether this is what you're looking for, but still there exists this plugin which can emulate the file/directory creation feature of Atom.
Since i use vscode-vim it's fairly easy to create new folders and files using command mode. If you're familiar with using terminal, then you can use shell commands to create file/dir.
I have no idea whether one could do what you had mentioned the proper way with vanilla vscode.
Hope this helps you somehow.