Last updated: Apr 6, 2024
Reading time·3 min
The easiest way to move a file to another folder in VS Code is to use drag and drop.
Once you drop the file into the new folder, you will be prompted for confirmation.
You can also drag and drop files from outside VS Code to Explorer to copy the file into your project.
If you drag and drop an external file into the main code Window in VS Code, its contents are shown but the file isn't copied into your project.
Notice that the import got automatically updated when I moved the file to a different folder.
To specify if you want to automatically update imports when a file is moved:
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.You can also open the settings screen by pressing Ctrl
+ ,
on Windows and
Linux or Cmd
+ ,
on macOS.
You can set the setting for JavaScript and TypeScript.
There are 3 possible values:
prompt
- when a file is moved, you get prompted whether you want to update
imports.always
- always update imports when a file is moved.never
- never update imports when a file is moved and don't prompt.You can also use the Ctrl
+ X
and Ctrl
+ V
keyboard shortcuts.
If you are on macOS, use Cmd
+ X
and Cmd
+ V
instead.
Ctrl
+ X
.Ctrl
+ V
.You can also use the arrow keys to navigate to the folder to which you want to move the file.
If you need to move multiple files to another folder:
Ctrl
(or Cmd
on macOS).You can also use the Shift
key to select multiple files and then use the
Ctrl
(or Cmd
) key to exclude ones you don't want to move.
You can also use an extension to move files in VS Code:
Ctrl
+ Shift
+ X
on Windows or Linux.Command
+ Shift
+ X
on macOS.Make sure to install the File Utils extension by Steffen Leistner as shown in the screenshot.
Once you install the extension:
Note that you have to specify the entire path to the new location.
For example, from:
/home/user/Desktop/bobbyhadz-vscode/index.js
To:
/home/user/Desktop/bobbyhadz-vscode/my-folder/index.js
You can also use the command palette to trigger the command:
Open the file you'd like to move.
Press:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.Here is a short clip that demonstrates the process.
I've also written a detailed guide on how to hide specific files or folders from the left sidebar.
You can learn more about the related topics by checking out the following tutorials: