4

Is there a way to set VSCode as the default text editor? I'd like to have it be default when opening a file from the command window and when using the files app.

When I right click on a file and select 'open with', VSCode doesn't show up on the list of possible apps, even after clicking "show other applications".

It also doesn't show up in the list of possible apps when I enter

sudo update-alternatives --config editor

in the command window.

Jon
  • 281
  • 3
  • 8

1 Answers1

2

To open with VSCode from Nautilus, create a .desktop file, open it in gedit, and paste in the following:

[Desktop Entry]
Name=VSCode
Comment=Edit code files
Exec=code %f
Terminal=false
Type=Application
Icon=code
Categories=TextEditor;
StartupNotify=true
MimeType=text/x-text;

Save the file, then move it to /.local/share/applications (you may need to open Nautilus via sudo Nautilus to be able to move it there). It should now appear in the "open with" dialogue when right-clicking on a file. Set VSCode as the default program for that file by right-clicking on the file, Properties, 'Open With' tab. The downside to this method is that it just opens the file, but not the folder in VSCode's 'Explorer' pane.

To open a file with VSCode from the terminal, follow the directions here (Linux section about 1/3 the way down), making sure the paths you use are absolute, not relative. Once that's working, if you cd to the directory you want and enter code . it'll open that folder in the VSCode's 'Explorer' pane.

Jon
  • 281
  • 3
  • 8
  • Set VSCode as the default program for that file by right-clicking on the file, Properties, 'Open With' tab. was what I was searching for. I thought I would have to add files for that, but in reality, I just had to do it with clicks "like in Windows", just in the properties was not what I expected. For me, the main thing was not to have a desktop launcher (which did not exist indeed in the list of /usr/share/applications which I use instead of /.local/share/applications), but that I did not know how to make it default at all. – questionto42 Mar 04 '22 at 09:52