Editing files in your Linux Virtual Machine made a lot easier with Remote VSCode
Ever since I started playing around with Python, machine learning and deep learning frameworks like Microsoft CNTK and TensorFlow, I’ve been starting to use virtual machines (specifically Azure Data Science Virtual Machine) in most of my time to write code and to train my models faster.
But one of the problems I had with editing files in my virtual machine is that the experience is TERRIBLE. Especially if you’re living here in the Philippines in where the internet connection is really SLOW, you’re really going to have a hard time editing files or writing code in your virtual machine.
So previously, I had two solutions to solve this problem:
- Using Vim — Vim is basically a lightweight text editor that allows you to write and edit a text by just using a keyboard to navigate throughout your code. The way I use this is simply by connecting to my Linux Virtual Machine via SSH and use the
vimcommand to edit the file inside the terminal.
But there’s three problems here:
a. Not everyone is a fan of command line/terminal. I know some people who hated it and who just simply prefer using GUI to do things.
b. The autocomplete feature is there, but it’s not as smart to what I got used to in terms of using Visual Studio IDE and Visual Studio Code.
c. Using Breakpoints for debugging. Breakpoints is one of the most useful feature I’ve ever used for debugging my code, and I was surprised that a text editor such as Visual Studio Code has one. Unfortunately for Vim, to my knowledge, there’s none.
2. Using WinSCP — WinSCP is a free, open-source file transfer application that uses FTP, SCTP, and SCP client specifically for Windows. This is a useful tool to edit your files in your virtual machine from your local machine while using the text editor of your choice.
To be honest, I‘m actually fine with this tool, because as you can see, I get to edit my files in my virtual machine to my local machine while using the text editor of my choice.
But then, the problem I had here is that, this software is only available for Windows. Because from time to time, I also use my Mac machine at work to do these kinds of things, and so far, I wasn’t able to find an equivalent software that I can use in my Mac.
Remote VSCode Setup
So this is where the Remote VSCode comes in. Remote VSCode is a Visual Studio Code extension that is available in all platforms supported by VSCode (yes, including both Windows and macOS), that implements the Textmate’s ‘rmate’ feature. This extension allows you to edit your files from your virtual machine a lot easier.
To use the extension, do the following:
- Launch Visual Studio Code, or install it here if you don’t have it yet
- Go to the ‘Extensions’ page and search for ‘Remote VSCode’
3. Install the extension and re-launch Visual Studio Code
4. In your Linux Virtual Machine, execute the following command in your terminal to install rmate
$ sudo wget -O /usr/local/bin/rmate https://raw.github.com/aurora/rmate/master/rmate$ sudo chmod a+x /usr/local/bin/rmate
5. Go back to your Visual Studio Code and open up the command palette (CTRL+P for Windows and CMD+P for Mac) then execute the
>Remote: Start Server command.
6. Once the server is ready, open up a new terminal and connect to your Linux Virtual Machine using the following command:
$ ssh -R 52698:localhost:52698 VIRTUAL_MACHINE_IP_ADDRESS
7. In your terminal, execute the
rmate command with the file that you want to open up in your Visual Studio Code in your local machine
$ rmate demo.py
Just in case you’re also wondering where the
52698 port came from, it’s actually the default port that Remote VSCode is using. You can find and change that setting by simply going to your ‘User Preferences’ and search for ‘Remote VSCode configuration’.
So what do you think about Remote VSCode? Do you find it useful or you’re already content with the current tool you’re using for editing files in your remote server?