英文:
Is it possible to paste files (not textual file contents) copied to the clipboard from other applications in VS Code?
问题
在VS Code资源管理器面板内,如果我想将文件复制到工作区的另一个目录,可以使用<kbd>ctrl</kbd>+<kbd>c</kbd>和<kbd>ctrl</kbd>+<kbd>v</kbd>。但是,如果我在计算机上的另一个应用程序(如本机文件资源管理器应用程序)中找到一个文件,首先按下快捷键<kbd>ctrl</kbd>+<kbd>c</kbd>,然后转到VS Code窗口并按下快捷键<kbd>ctrl</kbd>+<kbd>v</kbd>在资源管理器面板中,这没有效果。
请注意,我不是在谈论复制文件的_内容_并粘贴到VS Code。我在谈论复制"文件",即桌面环境中的文件概念。
解决方法是使用本机文件资源管理器,首先复制文件,然后打开在VS Code中打开的文件夹,最后在本机文件资源管理器中粘贴它。但我觉得这样很麻烦。
是否有更简单的方法可以做到这一点?VS Code是否支持从不同应用程序(不是VS Code)复制到剪贴板的文件并粘贴到VS 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 <kbd>ctrl</kbd>+<kbd>c</kbd> and <kbd>ctrl</kbd>+<kbd>v</kbd>, but if I find a file from another application on my computer such as the native File Explorer application, first pressing the shortcut key <kbd>ctrl</kbd>+<kbd>c</kbd> and then going to the VS Code window and pressing the shortcut key <kbd>ctrl</kbd>+<kbd>v</kbd> 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?
答案1
得分: 0
Vscode支持从本机文件浏览器(至少在Windows上)拖动文件名并将其放在要放置的位置的 vscode 的资源管理器中。
你也可以使用操作系统的“打开方式...”功能,然后将编辑器的选项卡拖动到您想要的目录中。
英文:
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.
答案2
得分: 0
在撰写本文时,这个功能尚不受支持...但有计划支持!
实现此功能的工作已在此 GitHub 问题中跟踪:Explorer: 允许从剪贴板粘贴文件到目标文件夹 #130036,这是跟踪更大努力的一个子任务,该努力旨在实现更好的拖放/剪贴板文件集成,问题编号为 #164。
您可以通过给该问题添加点赞反应来表达您对该问题的支持,但请不要发表"me too"评论。"me too"评论通常会让仓库维护者感到烦扰,因为它们会混淆讨论并没有提供重要的价值。
VS Code 仓库的贡献者 pingren 尝试实现这一功能,但发现它比看起来要复杂。您可以在他们在评论中的解释中了解原因。其中一个困难来自于与系统快捷键和 VS Code 重新映射键的集成:
onPaste
事件只能由系统粘贴(在 macOS 上为 cmd+V)触发。用户可以将filesExplorer.paste
命令更改为任何快捷键。因此,我们需要考虑如何合并来自剪贴板的本机粘贴和 VSCode 文件资源管理器粘贴。
还有另一个功能请求问题(从本机资源管理器复制粘贴文件到 VSCode #89862,创建于 #130036 之前),其中另一位 VS Code 贡献者 isidorn 发表了评论:
这是一个合理的功能请求,但我认为有一个 Chrome 限制,阻止了我们实现这个功能。
至于可能执行此操作的扩展程序,我不知道有哪些(但也没有刻意搜索过)。
其他可能的解决方法包括:
-
尝试将文件从本机文件资源管理器应用程序拖动到 VS Code 文件资源管理器面板。至少在 Windows 和 Ubuntu 上已确认可以正常工作。
-
从 Mark 的回答(在 CC-BY-SA 下复制):
您还可以使用操作系统的“打开方式...”功能,然后将编辑器的选项卡拖到您想要的目录中。
-
从 user103 的回答(在 CC-BY-SA 下复制),并在问题帖子中部分提到:
您可以选择从“文件”中选择“添加文件”以将文件添加到工作区。或者您可以使用“文件”中的“新建文件”来创建工作区
英文:
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.
<sup><sub>You can show your support for the issue ticket by giving a thumbs up reaction to the issue. But please don't make a "me too" comment. "me too" comments generally come off as annoying to repo maintainers because they clutter up discussion and don't contribute anything of significant value.</sub></sup>
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'sOpen 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 chooseAdd File
fromFile
to add a file to your workspace. Or you can useNew File
fromFile
to create a new file in your workspace and copy the content of the file outside to it.
A PR has been drafted here: https://github.com/microsoft/vscode/issues/130036#issuecomment-1765241272.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论