Reputation: 10190
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:
set directory=~/.vim/swaps//; set backupdir=~/.vim/backups
The solutions are helpful but require setup of vcs, config files, etc.
I'd prefer
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.
Upvotes: 9
Views: 2653
Reputation: 883
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.
Upvotes: 2
Reputation: 10190
Plugin AsyncRun for vim8/neovim
describes on following wiki page how to get netrw using this plugin when saving to remote:
https://github.com/skywind3000/asyncrun.vim/wiki/Get-netrw-using-asyncrun-to-save-remote-files
Copy of the patch:
Following diff to $VIMRUNTIME/autoload/netrw.vim (version 156) saves asynchronously with AsyncRun when you put into your vimrc let g:netrw_write_AsyncRun = 1:
❯ git diff netrw-156.vim netrw.vim
diff --git a/netrw-156.vim b/netrw.vim
index 76485c2..183fc96 100644
--- a/netrw-156.vim
+++ b/netrw.vim
@@ -510,6 +510,7 @@ call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
call s:NetrwInit("g:netrw_win95ftp",1)
call s:NetrwInit("g:netrw_winsize",50)
call s:NetrwInit("g:netrw_wiw",1)
+call s:NetrwInit("g:netrw_write_AsyncRun",0)
if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
" ---------------------------------------------------------------------
" Default values for netrw's script variables: {{{2
@@ -2377,6 +2378,14 @@ fun! netrw#NetWrite(...) range
" call Decho("(netrw) Processing your write request...",'~'.expand("<slnum>"))
endif
+ " NetWrite: Perform AsyncRun Write {{{3
+ " ============================
+ if exists("g:netrw_write_AsyncRun") && g:netrw_write_AsyncRun == 1
+ let bang_cmd = 'AsyncRun -post=call\ delete('.s:ShellEscape(tmpfile,1).')\ |\ echo\ "(netrw)\ Your\ write\ request\ has\ finished." '
+ else
+ let bang_cmd ="!"
+ endif
+
".........................................
" NetWrite: (rcp) NetWrite Method #1 {{{3
if b:netrw_method == 1
@@ -2515,7 +2524,7 @@ fun! netrw#NetWrite(...) range
else
let useport= ""
endif
- call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1))
+ call s:NetrwExe(s:netrw_silentxfer.bang_cmd.g:netrw_scp_cmd.useport." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1))
let b:netrw_lastfile = choice
".........................................
@@ -2612,9 +2621,11 @@ fun! netrw#NetWrite(...) range
" NetWrite: Cleanup: {{{3
" call Decho("cleanup",'~'.expand("<slnum>"))
- if s:FileReadable(tmpfile)
-" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
- call s:NetrwDelete(tmpfile)
+ if !exists("g:netrw_write_AsyncRun") || g:netrw_write_AsyncRun == 0
+ if s:FileReadable(tmpfile)
+" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
+ call s:NetrwDelete(tmpfile)
+ endif
endif
call s:NetrwOptionRestore("w:")
Upvotes: 0
Reputation: 10190
SSHFS: My Problem with sshfs was the vim plugin lightline.vim
using fugitive.vim
function.
The statusline is updated quite often when you scroll (line number changes) and therefore the fugitive function to show the current branch was evaluated all the time.
This slowed the scrolling significantly down. Removing fugitive status from statusline alleviated the slow down.
There is another plugin https://github.com/seletskiy/vim-refugi which reports that
git through sshfs is slow as hell.
I also installed this plugin for fugitive and applied their tip
Because this script uses ssh multiplexing, it is good to configure your ssh to automatically open master connections.
E.g. you need this in your ~/.ssh/config:
host *
controlmaster auto
controlpath ~/.ssh/connections/%r_%h_%p
Upvotes: 0