VSCode :: How can I duplicate directories and files from within the file explorer? - visual-studio-code

Ideally, I would right-click on the folder/directory or file I want to duplicate, choose "Duplicate" and, hopefully, would be asked in the same step to give the new duplicated file or directory a new name.
Looking at the current options, I couldn't find a way to do this on latest VSCode 1.19.1 (macOS):
Am I missing something? Is there other way to do this?
The more I use VSCode, the more I get used to it and, lately, I found myself barely needing to use the terminal provided in the Panel, or switching to a terminal app, for simple stuff like this.

Marketplace extension File Utils:

To duplicate a file within a folder.
On the explorer pane:
right click on the file,
press copy
now right click on the folder, and
press paste
the file will be duplicated into the same folder with "...-1" or " copy" appended to the file name

The "Duplicate action" extension will allow you to right click and choose duplicate as you described.

A somewhat old issue now but as I try to avoid installing too many extensions this may be helpful to others wanting to avoid the same. Also, as there's a strong chance this is a context in which you're using a mouse/trackpad (as opposed to keyboard), the normally fantastic 'do everything' quick menu thing (or whatever Shift + CMD + P is called) is probably not a great solution...
Hold down Alt. (Note: You can actually do this during step 2 if preferred).
Drag the file onto the folder it is already in (during drag the cursor will have a green plus icon).
Release the file where you want it to be (doesn't actually have to be the same folder).
The file will be duplicated with the filename {original-filename} copy.{original-extension}.
Click on the file again.
Hit enter/return to edit the filename.
All the above sounds much more onerous than it really is. I find it quicker than right-clicking and momentarily finding/navigating to a menu option, especially if that menu option is not a native one.

How about the good old CTRL+C and CTRL+V?
I just tried. If you click on a file then press CTRL+C, and then CTRL+V then you get a duplicate of the file named [original name] copy.[ext]
It's a mystery, though, why the duplicate file option is still not on the right-click menu after so many years.
A little warning: doing this will remove the content of the clipboard. So if you are in the middle of a copy-paste cycle, then make sure to save the clipboard content somewhere. Yes, it's inconvenient, but until MS decides to put in this basic action in the context menu (right-click) we need to deal with it.

Atleast in Linux, holding down Ctrl and dragging the file into the required directory should do the trick. No Ctrl+C Ctrl+V required.

CTRL+C
CTRL+V
F2
type new name
ENTER
opens in editor
Similar to above but with an extra couple of things

Another solution, since VS Code still does not allow this in 2022:
Install the multi-command package.
Then, in your keybindings.json add the following:
{
"key": "cmd+d",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"filesExplorer.copy",
"filesExplorer.paste"
]
},
"when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !inputFocus"
}
Afterwards, you can press CMD + D to duplicate a file or folder.
You may want to add "renameFile" into the sequence to directly rename the duplicate. Of course, this works just as well with ctrl instead of cmd.

Related

Can't edit files in Vscode

I've just started using Vscode and have a created a WebAPI project. On trying to open any of the default code files (Startup.cs and Program.cs) whatever I type starts to appear in the blue bar as shown below instead of where I have placed the cursor. I have no idea what's going on or what that blue bar is.
I am able to add my own code files and edit these as I would expect.
I'm running Vscode 1.29.1 on Win 10 on a Dell Latitude 12 7275. The vscode extension
Enabled extensions :
That's caused by Vim extension. Uninstall or disable it, otherwise use insert key on your keyboard to put it in insert mode.
I'l leave this here for future readers
Basically, if I split files in tabs in VS Code, I could work with the files on the left hand side but could "read-only" all the files on the right hand side.
When I went to the extensions tabs I noticed that whatever I typed was being typed in the field in the extensions search bar. After deleting that, and clicking back on the "Files" tab, it went back to normal and can basically edit files on the both sides of my split screen.
If cannot type
Check where whatever you type is going (e.g. Extensions > Search bar)
Delete wherever it's being typed, and click back on the "Files tab"
Check if it works
I had to change the parent folders permission...
Try changing the entire folder to:
Read & Write: Allows a user to open the item and change it.
https://support.apple.com/guide/mac-help/change-permissions-for-files-folders-or-disks-mchlp1203/mac

How to get VSCode to "open as new file" from Go To File dialog

I have recently switched to VSCode, and am loving it, except for one specific thing that drives me nuts.
My "goto" command is {Command+P}, the easy search-and-open-file bar. If I type the name of a file into this bar and it does not exist, I want to be able to hit ENTER and have it open a tab editing that file as a new file. This is the behavior I would get in old-school Windows Notepad, or in mvim :e <filename>, but I can't figure out how to do it in VSCode.
Is there a toggle or a plugin I can use to get this behavior straight out of the Go To File dialog?
Answering my own question:
No, there's no way to do this using {Command+P}. This is strictly a file finder and I've yet to see any plugin that changes the behavior.
If you're using the VsCodeVim plugin, an almost-as-good approach is just :e <file> - immediately open a new buffer editing the given file. There's no tab autocomplete this way, but you just have to live with that.

Removing a file or folder using VS Code

When I bring up VS Code I see options for adding a file or folder but I do not see options to delete a file or folder or rename such. Any hints?
Deleting file is strait forward. To delete a folder created using MS Code explorer,
press Ctrl + Shift + P then it will show a command prompt like
section at top.
Search 'remove' in that. A command will be shown -"Workspaces: Remove folder from workspace...". Click on that.
Intended folder name will be shown for removing.
After clicking the same, it will be removed from explorer, without affecting actual
files on the operating file system.
Thank you I figured it out. It doesn't seem immediately obvious to me but on a MAC using VSCode selecting a file and entering the return key lets you rename a file, selecting a file and then using command-del deletes a file.
The Rename and Delete actions are there, but you have to select the file in the bottom part of Explorer, under the project directory. When you select it under Open Editors or right click on the tab bar, there is no Delete and that is confusing. In this case you can choose Reveal in Side bar in the tab context menu to get to that entry. But that won't help (will select the tab under Open Editors) if the file is out of the project tree, in this case the most convenient action would probably be to Open Containing Folder and delete it manually in the file manager.
Using extension:
Install File Utils extension
https://marketplace.visualstudio.com/items?itemName=sleistner.vscode-fileutils
Press Ctr + Shift + P
Type File Utils > Delete
In VSCode, make sure you are in Explorer. Also make sure you are right-clicking the file shown in the directory/folder. Here either hitting Del for windows and command+del for Mac will delete the file.
A common issue is trying to delete a file when in source control. You must be in explorer.
VSCode 1.50 (Sept 2020) still has the feature for file deletion, and improves it with microsoft/vscode issue 71315
##Should maintain row focus after deleting a file
Use case:
Use the keyboard to focus a file in the explorer and delete it
Now the whole tree has focus
Press the down arrow key
The first item is selected
I want to get back to where I was looking before.
The search tree focuses the next item in the list when one is removed.
I don't know whether the explorer did this previously with the old tree. But it would be nice for the explorer to do the same thing.
Just right click on the file or folder you will get the options to delete the file as well as of renaming the file.
For directory delete type in VScode terminal:
rm -r directoryName
For file delete type in VScode terminal:
rm fileName.tx
No way to delete a folder by a right-click. However, you may remove it from the IDE: File > Close Folder.

How to disable Ctrl-Click in VS Code

I want to know if it's possible to remove the key bind on Ctrl-Click for the goToDefinition (F12) editor action.
This is so annoying, every time i try to Ctrl+C/V it trigger and go to the definition cause I'm holding Ctrl while I'm highlighting the code with my mouse.
I have search for it on google but all y can change is the F12 key bind for goToDefinition which is not what I want.
--- Update
This is the feature I want to disable
I need to remove the ctrl+click key bind.
Even if I replace it, it doesn't work.
-- Update 2
I finally found something on the subject Here
But for me it doesn't work at all.
-- Update 3
Created a new issue on GitHub (#7827)
Look at it if you wanna see the update on the request.
At the time of writing (2022) you can turn off this with workaround by setting following setting to 'ctrlCmd'.
How to open setting page in vs code?
Ctrl+Shift+P and enter open setting (UI)
Note that if you are also looking for Ctrl+Click for word selection, it is still not possible. See my another answer.
And yea, the dreaded (and famous) issue #3310 is never really happened, even after 6 years.
There is a VS Code feature request for this on GitHub, under the more general heading Allow customization of mouse shortcuts.
Anyone interested in this VS Code feature should comment/vote there. (The Ctrl-click-specific GitHub posts have been closed off and linked to this one. Ex. #16974)
Add the following lines in keybingings.json to disable (actually override default behaviour) mouse+ click
[
{ "key": "ctrl+[mouse button]", "command": "cursorWordLeft",
"when": "editorTextFocus" }
]
To open key bindings file, traverse
File > Preferences > Keyboard Shortcuts

IntelliJ Macro menu

I've just started playing with macros in IntelliJ. I recorded several then played back until I decided to add keymap shortcuts to my macros. I went to Settings and pressed Alt+C to add a new child map because I couldn't edit the parent. Since then the macros are no longer accessible from the Tools menu, not to mention that the shortcuts don't work. I tried removing the shortcuts from the keymap but even though I press Alt+R or Alt+L, it still does not revert them back. And TAB has stopped working .. when writing sout +TAB ..nothing happens anymore... HELP
Sorted! sout+TAB is part of live templates..
If you open the IDE Settings window, you will see Live Templates.. Under output you should find sout(Prints a string to System.out).. if not, click Add and then type sout for the Abbreviation section, type in a description and then for the template text put System.out.println("$END$");
I use the Default keymap in IntelliJ now...
Thought this might help someone...
You can try to use the default keymap. When you modify the default keymap, a copy is created with your settings.
If that is not working, you can try to quit IntelliJ and to delete this file:
/.IntelliJIdea90/config/options/macros.xml
and check also for the folder
/.IntelliJIdea90/config/keymaps
To find the location of the config folder you should look for the file : idea.properties in the folder where the main executable for idea is.
Look for the line:
# path to IDEA config folder. Make sure you're using forward slashes
idea.config.path=${idea.home}/.IntelliJIdea90/config
And this is the location of the config. folder.
Restart IntelliJ.
Take a copy of any file you are going to delete!