A lightweight Neovim plugin to sync your local code to remote servers with minimal configuration. Runs in background, does not freeze the main window.
- I wanted a simple, minimal plugin to sync code from my local machine to a remote server while coding in Neovim—my go-to editor.
- Existing plugins were either too bloated or difficult to configure.
- So I built this: a single-purpose, Lua-based plugin that does one thing well—syncing code from local to remote.
- You just need to define your sync configuration in
~/.config/.code_sync.lua, and you're ready to go! - If you find this plugin useful and want to contribute, check out the 🛠️ Future Todos section.
Install using packer.nvim:
use({
"ayush-garg341/code_sync",
config = function()
require("code_sync").setup()
end,
})Or refer to this config reference.
- Support the dry run so that you can see the actual changes that will be made without actually making change.
- Hot reload the config file i.e when you make any change in sync configuration file
~/.config/.code_sync.luathe changes will reflect in the next sync command. - All floating windows closes by ESC. You can map this key to something like caps lock to ease.
Save your config in: ~/.config/.code_sync.lua
{
protocol = "rsync",
["data-science"] = {
test = {
{
target = "ayush@<hostname>:/home/ayush/data-science",
exclude_file = "/Users/elliott/.rsyncignore",
keypath = "~/Downloads/some.pem",
method = "key_based"
}
}
},
...
}Steps:
ssh-keygen -t rsa -b 4096 -C "yourname@yourhost"
ssh-copy-id -i ~/.ssh/id_rsa.pub user@hostUpdate ~/.ssh/config for shorthand access:
Host myserver
HostName 192.168.1.42
User ubuntu
IdentityFile ~/.ssh/id_rsa
Host workserver
HostName 10.0.0.5
User devops
IdentityFile ~/.ssh/id_workSample Lua config:
{
protocol = "rsync",
["project-name"] = {
test = {
{
target = "myserver:/home/ubuntu/project-name",
exclude_file = "~/.rsyncignore",
method = "key_less"
}
}
}
}Install sshpass:
# Linux
sudo apt install sshpass
# macOS
brew install hudochenkov/sshpass/sshpassLua Config:
{
protocol = "rsync",
["project-name"] = {
test = {
{
target = "user@host:/home/user/project-name",
keypath = "yourpassword",
method = "pwd_based"
}
}
}
}Let's understand the keys used in the config:
- protocol: One of the supported sync methods:
scp,rsync,ftp,sftp.
(Currently, onlyrsyncis supported.) - keypath: Path to the SSH private key (
.pem) file for authentication. - ["data-science"], user_agent, redis_full_dv_process, ...:
These represent the currently opened project names in Neovim which you want to sync. These act as sources.- test, stage, dev:
Environment keys indicating where the code should be synced.- Each environment key holds an array of targets.
(You can sync code to multipletest,stage, ordevservers.)
- Each environment key holds an array of targets.
- target: Destination server and directory where code should be synced.
- exclude_file: Path to a file like
.rsync_ignorethat lists files/folders to be excluded from syncing (similar to.gitignore). - exclude: Inline list of files/folders to be excluded (array).
- test, stage, dev:
- Define ports in your
~/.ssh/config:
Host mypi
HostName 192.168.1.100
User pi
Port 2222
IdentityFile ~/.ssh/id_rsa- Or modify the
targetstring to include-p <port>before the SSH address.
Three commands are currently supported:
| Command | Description |
|---|---|
:CodeSync |
Syncs code to the defined environment (test/stage/dev). |
:CodeSyncList |
Shows running sync jobs with their job IDs. |
:CodeSyncCancel |
Cancels a sync job given its ID. |
:CodeSync test --project " Sync entire project to test env
:CodeSync test --cwd " Sync current directory to test env
:CodeSync dev " Sync current opened file to dev env
" To dry run the command ( emphasize safety ), add the option --dry at the end of the command.
:CodeSync test --project --dry " Dry run entire project to test env❗Note: prod sync is intentionally not supported. Production sync should go through CI/CD pipelines.
- 📊 Better logging for sync success/failure
- ⏱️ Auto-sync at user-defined intervals
- 🧠 Smarter file tracking and change detection
- ✅ Add support for
scp,sftp.
All contributions are welcome! 🚀
- Fork the repository
- Create a new branch:
git checkout -b my-feature - Make your changes and test thoroughly
- Soft link the project code to your packer folder where you have all other neovim packages to test the functionality you added.
ln -s ~/personal/code_sync /Users/elliott/.local/share/nvim/site/pack/packer/start/code_sync # To link the code
rm -rf /Users/elliott/.local/share/nvim/site/pack/packer/start/code_sync # To remove the old link- Commit and push:
git commit -m "Add new feature"thengit push origin my-feature - Open a Pull Request with a description of what you’ve changed
Made with ❤️ by @ayush-garg341