Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save in vim a remote file asynchronously?

Edit a remote file with

 vim scp://remote/file

Saving the file with :w blocks the editor till the file changes are saved to the remote.

I was trying to use :Dispatch :write to avoid being blocked but that does not work (using tmux or iterm strategy). :Dispatch is provided by the plugin vim-dispatch.

Relevant internet search results suggest:

  • Ssh to remote and work there (if you have a slow connection, check this question or consider ssh-alternative mosh)
  • eshion/vim-sync offers the possibility to autosync changes of a local file to the remote
  • Git hook auto-push: after each commit push changes to the remote
  • satiani/async-scp-vim (see for details blog) launch SCP calls whenever the BufWritePost event is triggered
  • Ssh tunnel faster write due to open ssh connection (see also Speeding up Vim's Netrw plugin over ssh/scp and autossh).
  • sshfs/osxfuse-sshfs set directory=~/.vim/swaps//; set backupdir=~/.vim/backups
  • Neovim no release yet and nightly build does not do it out of the box. Any answer here appreciated. It has been reported as an issue #1464
  • Backchannel Vi

The solutions are helpful but require setup of vcs, config files, etc.

I'd prefer

  • to work locally
  • no configuration for each file (configuring the editor once and for all is ok)
  • Not every write should be a commit.

Keeping an ssh tunnel open didn't improve it either.

Update I'd like to know whether there is a solution to run the save process asynchronously. The save process means here, as netrw is showing in the commandline, a scp call to copy the temp file to the remote which can take some time. I'd like to return to my editing in the meanwhile and don't be blocked. I hope this makes my question clearer.

Alternatives to tpope/dispatch are: Shougo/vimproc, idbrii/AsyncCommand, which I haven't tried yet.

like image 237
Hotschke Avatar asked Mar 01 '15 16:03

Hotschke


1 Answers

It was an old question, yet I encountered the same problem of how to work with remote files efficiently.

My solution is to use unison to sync files on the fly. A command is defined to call the sync function within vim.

function! s:Sync()
  call system("unison -batch /home/user ssh://user@server//home/user")
endfunction

command! Sync :call <SID>Sync()

The speed of sync files using unison is so fast that I don't have much motivation to make it run asynchronously.

like image 112
Gang Liang Avatar answered Nov 04 '22 09:11

Gang Liang