Sometimes, the OS open a new VSCode instance when you want to open a directory (via
xdg-open) with the default file manager (such as
The OS chooses an application when opening a file (directory is a special file type, called
inode/directory, in this case) is called "Default applications".
If VSCode is chosen to be the default application for
inode/directory, whenever you want to open a directory from the command line (
xdg-open directory-path), VSCode will be used.
The OS determines the default application by reading the configuration from several files:
To check the default application for a specific file type
Such as checking the default application for opening a directory
xdg-mime query default "inode/directory"
gio mime inode/directory
Default application for “inode/directory”: org.gnome.Nautilus.desktop Registered applications: org.gnome.Nautilus.desktop code.desktop Recommended applications: org.gnome.Nautilus.desktop code.desktop
Why VSCode is chosen to be the default directory opener
VSCode IDE has the ability to open a directory, which is defined in
inode/directory entry in the assigned value of
MimeType specify for the ability to open a directory of VSCode. When being installed, this file is stored at
When installing/updating VSCode, the OS mistakenly re-organize the mimetype file at
/usr/share/applications/mimeinfo.cache, and the OS resets the default directory (
inode/directory) opener to be VSCode.
Phenomenons with IDEA editors
The "Open In" menu in any IDEA editor is changed from "Files" to "Visual Studio Code".
Screenshots after pressing
Screenshots of the right-click menu:
This solution prevents the restoration of VSCode being the default directory opener, in the future VSCode update.
Step 1: find out the default entry of
cat /usr/share/applications/mimeinfo.cache | grep
Step 2: override the default with a local configuration.
Edit, or create if the file does not exist,
[Default Applications] inode/directory=org.gnome.Nautilus.desktop;code.desktop;
This method is described by gnome here.
You can directly and manually edit the configuration file which causes the issue
Check the result with
xdg-mine described previously in this post (link).
# xdg-mime query default "inode/directory" code.desktop # gio mime inode/directory Default application for “inode/directory”: code.desktop Registered applications: code.desktop org.gnome.Nautilus.desktop Recommended applications: code.desktop org.gnome.Nautilus.desktop
# xdg-mime query default "inode/directory" org.gnome.Nautilus.desktop # gio mime inode/directory Default application for “inode/directory”: org.gnome.Nautilus.desktop Registered applications: code.desktop org.gnome.Nautilus.desktop Recommended applications: code.desktop org.gnome.Nautilus.desktop