views:

326

answers:

2

Hey all,

I'm looking for a way to map the :w command so that when I use it, it will rsync the current directory and save the file in question. Ideally, the response generated by the rsync command should be returned in vim, but not in the the current file, but rather as a tooltip or something.

I managed to achieve this in TextMate and am now looking to start working with Vim. I've been trying things like :map w :w|!rsync . but that doesn't seem to work (I'm a beginner :))

I'd appreciate any help.

Thanks, Joe

+4  A: 

You can hook into BufWritePost. I don't remember the exact syntax, but ":he BufWritePost" and ":he autocommand" should help you.

You setup a basic hook like this (pattern matches on a file, so you can do *.your_extension):

 :au BufWritePost * !rsync

Also, there should be some way to make it buffer-local.

viraptor
+1  A: 

If you want to keep the local copy, then the BufWritePost autocmd suggested by viraptor is the best bet, but assuming you have the netrw plugin installed (part of the default Vim runtime files), you can also start vim with:

vim rsync://myrsync_server.com/path

and just edit the file as if it's local: saves will update the remote server.

:help rsync
Al