Vim publishing script
I'm looking开发者_JAVA百科 for a vim script that, when I save, duplicates my changes to a second directory. In this case the second directory is on a VM that I can ssh to. Any suggestions?
If you want to do it manually add this to your vimrc:
command! DuplicateFileRemotely !scp % user@remotehost:~/mylocation/
Then call it in command mode:
:DuplicateFileRemotely
If you want to do it every time a file is saved add this too your vimrc as well:
autocmd! BufWritePost * :DuplicateFileRemotely
If you can access the filesystem locally then you can use cp. Add this to your your .vimrc and change the path.
autocmd BufWritePost,FileWritePost *.* silent !cp <afile> /your/remote/path &
If you can only access ssh then use scp or rsync.
autocmd BufWritePost,FileWritePost *.* silent !scp -Cr <afile> ssh://hostname:remote/path &
If you just want this to happen for certain file extensions change the *.*
to say *.py
to only copy Python files for example.
you can set up a key mapping to write to 2 locations, for example:
map <C-s> :w<ENTER>:w /path/to/alt/dir/%<ENTER>
This will map Ctrl-s to to you double save, saving the file to it's current location and also to your alternate directory with the same file name.
Vim can automatically save copies to a "backup directory" (assuming you can map the location on your local filesystem). See :h backupdir
for more information on this option, or view help on the web here: http://vimdoc.sourceforge.net/htmldoc/options.html#%27backupdir%27
精彩评论