Though remote development is not available out of the box for Sublime Text, we can enable a form of it with the sublime-rsync-ssh package. This versatile plugin has many features and options, but this post will focus solely on syncing a single local folder to a remote folder. I recommend you peruse the README for more information.
Prerequisites
Sublime Text with macOS is used in the examples, but it’s still applicable for Windows and Linux. Cygwin is required for Windows.
a. SSH Public Key Authentication is configured with the remote host.
grep -A 4 'arch' ~/.ssh/config
My remote host is named arch
with the following attributes for the connection:
Host arch
Hostname 192.168.137.52
AddressFamily inet
User marc
PasswordAuthentication no
b. The git
tool is installed on the local host.
type -p git
c. The rsync
tool is installed on both the local and remote host.
type -p rsync && ssh arch 'type -p rsync'
Steps
- Create the project folder to be synced on both the local and remote host.
mkdir -p ~/Dev/foo && ssh arch 'mkdir -p ~/Dev/foo'
- Create the
hello.py
file in the local project folder.
printf 'print("Hello, World!")\n' > ~/Dev/foo/hello.py
- Open the project folder in Sublime Text.
subl ~/Dev/foo
Add the GitHub repository to Package Control.
- Open the Command Palette
- Enter
Package Control: Add Repository
- Enter
https://github.com/davidolrik/sublime-rsync-ssh
Install the package.
- Open the Command Palette
- Enter
Package Control: Install Package
- Enter
sublime-rsync-ssh
Append the
rsync_ssh
template configuration to thesettings
section of the project file.- Open the Command Palette
- Enter
rsync ssh: Initialize settings
Save the project file in the project folder.
- Open the Command Palette
- Enter
Project: Save As
- Enter
foo.sublime-project
Edit the project file.
- Menu: Project → Edit Project
For my example Python project:
- Exclude folders and files to be synced at the global level
- Define the
foo
remote (destination) - Sync the file when saved
{
"folders": [
{
"path": "."
}
],
"settings": {
"rsync_ssh": {
"excludes": [
".git*",
"*.sublime-*",
".venv"
],
"remotes": {
"foo": [
{
"command": "rsync",
"enabled": 1,
"remote_host": "arch",
"remote_path": "/home/marc/Dev/foo"
}
]
},
"sync_all_on_save": false,
"sync_on_save": true
}
}
}
Reopen the project for the new configuration to take effect.
- Menu: Project → Close Project
- Menu: Project → Open Project
- Select the
foo.sublime-project
file - Click the Open button
Perform a manual sync.
- Keyboard: ⇧ + ⌘ + F12
- Menu: Project → Rsync SSH → Sync Project to remotes
- Verify the
hello.py
file has been synced to the remote project folder.
ssh arch 'cat ~/Dev/foo/hello.py'
- Optionally, check the Console output for verification and troubleshooting.
- Keyboard: ⌃ + `