To use Visual Studio Code editor to edit files on a Raspberry Pi, pls. execute the below steps:
Make sure you have a RPi3 or 4 since it doesn't seem to be running on RPi2 and lower (really?)
Open Visual Studio Code
Install Remote Development extension pack. This contains:
WSL
Remote SSH
Dev Containers
Remote - Tunnels
We only need Remote SSH for the moment...
Run the key combination Ctrl-Shift-P to open the VS Code command palette
Type in Remote SSH and select the item Remote SSH: Connect current window to host (the option Remote SSH: Connect to host... will open a new window)
In the pull-down menu, select the session you want to connect to or create a new SSH Host.
When creating a new SSH Host you will be asked for the user name (pi) and host. Host can be the IP address or the host name.
Example: pi@thisismyrpi or pi@192.168.25.145
A new entry will be made in the config file. To edit the config file run the command Remote SSH: Open SSH Configuration File...
Note: in the configuration file, make sure you add the user name to the host name. This is currently a flaw in VS Code.
If you don't do this, your Windows user name will be used in the connection command instead of the user name pi for the RPi!
And that will fail!!!
So, make sure your Host section in the configuration file starts like so:
Host pi@thisismyrpi
or
Host pi@192.168.25.145
If all goes well, VS Code will install some files on the RPi (if it's the first time you connect to the RPi from VS Code) after you've given the RPi password and start the communication