Neovim plugin for synchronization with remote servers
Tags: neovim, ssh, nvim, vim
Published: 2023-11-01 15:16:04

[Transfer.nvim](https://github.com/coffebar/transfer.nvim) is a Neovim plugin that enables you to synchronize files between your local machine and a remote server using rsync and OpenSSH. It is a lightweight and user-friendly plugin suitable for syncing various types of files, including code, configuration files, and documents.

It's integrated with nvim-notify and will show you the status of the transfer in the animated colorful notification.

## Features

- File Synchronization using rsync and OpenSSH.
- Lua Configuration: Configuration for synchronization is written in Lua, making it accessible for those familiar with Neovim configuration.
- Excluded Paths: Excluded paths can be defined to avoid synchronizing specific directories.
- Commands includes creating a configuration file, opening a diff view, repeating the last transfer command, uploading, downloading, and directory diff.
- Customization: Change deployment config template, rsync params, keybindings.
- Notifications: Integrated with nvim-notify.

## Who Benefits from Transfer.nvim

Transfer.nvim is a valuable tool for individuals who regularly need to synchronize files with remote servers, including:

- Developers: Developers often require file synchronization between their local machines and remote development servers. Transfer.nvim simplifies and streamlines this process.
- System Administrators: System administrators can edit configuration files locally and upload them to the server with ease using Transfer.nvim.
- Users with Multiple Devices: Whether you need to sync files between your work computer and home computer, [Transfer.nvim](https://github.com/coffebar/transfer.nvim) makes the process more straightforward.

It's important to note that the synchronization configuration is written in Lua, making it accessible for those familiar with Neovim configuration. To simplify configuration, you can create the configuration file using the `:TransferInit` command.

#### Deployment config example

```lua
-- .nvim/deployment.lua
return {
  ["example_name"] = {
    host = "myhost",
    username = "web", -- optional
    mappings = {
      {
        ["local"] = "live", -- path relative to project root
        ["remote"] = "/var/www/example.com", -- absolute path or relative to user home
      },
      {
        ["local"] = "test",
        ["remote"] = "/var/www/test.example.com",
      },
    },
    excludedPaths = { -- optional
      "live/src/", -- local path relative to project root
      "test/src/",
    },
  },
}
```

You only need to edit this configuration to specify which local directory corresponds to which remote directory on a server. You can also define excluded paths.

## Installation

With Lazy.nvim:

```lua
{
  "coffebar/transfer.nvim",
  lazy = true,
  cmd = { 
    "TransferInit", 
    "DiffRemote", 
    "TransferUpload", 
    "TransferDownload", 
    "TransferDirDiff", 
    "TransferRepeat"
  },
  opts = {},
},
```

## Commands

- `TransferInit` - Creates a configuration file and opens it for editing.
- `DiffRemote` - Opens a diff view with the remote file.
- `TransferRepeat` - Repeats the last transfer command (except TransferInit, DiffRemote).
- `TransferUpload [path]` - Upload.
- `TransferDownload [path]` - Download.
- `TransferDirDiff [path]` - Compares the local directory with its remote counterpart and displays the changed files in the quickfix.

## Keybindings

`Transfer.nvim` does not provide any keybindings by default. The only exception is the `<leader>b`, which is mapped to remote buffer in diff view to close it with `:diffoff` and `bdelete`. You can change or disable this mapping in the opts.

Also, You can find pre-made solutions on the plugin page. Copy them to add all commands to your which-key keybindings and to the Neo-tree.

## Current limitations

- Auth only by ssh key (passwordless).
- You can have multiple servers, but you need to map one local directory to one remote directory, not one to many.
- You can't change deployment config path. It's not an issue, file doesn't contain any sensitive data.
- Windows is not supported.
- If you need auto-upload on `BufWritePost` event - it is on you.

Probably, some of this may change after the publication of the article. Pay attention to the date and the current README of the plugin.

It might be a good idea to add support for Amazon S3, Google Cloud Storage, and other cloud storage services in the future.

## Conclusion

[Transfer.nvim](https://github.com/coffebar/transfer.nvim) offers a user-friendly and efficient solution for individuals seeking hassle-free file synchronization in their Neovim environment. Streamline your workflow and stay in control of your data with this feature-rich plugin.