sponsor Vim development Vim logo Vim Book Ad

DuplicateWrite : Cascade the writing of a file to another location.

 script karma  Rating 1/1, Downloaded by 301    Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
script type
Though you should use scripts for automated deployment and version control for
merges, sometimes, you need to quickly duplicate a file to another file system
location whenever it is changed.
This plugin defines a :DuplicateWrite command that sets up additional
:write targets. From then on, whenever you save that buffer, the write is
cascaded to the additional files. Thus, when editing a script in your project
directory, you can have it immediately copied to the install directory that is
in the PATH. Or, with the help of the netrw plugin, you can even
automatically upload a locally edited HTML page to the remote web server.

The plugin hooks into the BufWritePost event to issue additional :write!

:DuplicateWrite {file}|{dirspec}
                        Create a cascaded write of the current buffer to the
                        specified {file}, or to a file with the same filename
                        located in {dirspec}. From now on, whenever the buffer
                        is |:w|ritten, it will also be persisted to the passed
                        location. (Until you :bdelete it.)
                        You can issue the command multiple times (with
                        different {file} targets) for a buffer to add cascades
                        to several concurrent locations.

:DuplicateWriteOff      Turn off all cascaded writes for the current buffer.

:DuplicateWriteList     List the cascaded write target(s) for the current

:DuplicateWriteListAll  List the cascaded write target(s) for all open
                        buffers that have any. The buffers are listed with
                        their number followed by the name; the targets are
                        listed in the following, indented lines, for example:
                        4  "DuplicateWrite.txt" ->
install details
This script is packaged as a vimball. If you have the "gunzip" decompressor
in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress
the archive first, e.g. using WinZip. Inside Vim, install by sourcing the
vimball or via the :UseVimball command.
    vim DuplicateWrite*.vmb.gz
    :so %
To uninstall, use the :RmVimball command.

- Requires Vim 7.0 or higher.
- Requires the ingo-library.vim plugin (vimscript #4433), version 1.013 or

The filespecs of the cascaded write targets are stored in the buffer-local
List variable b:DuplicateWrite. You can use its existence / number of elements
to determine whether / how many duplications are configured, and use this e.g.
in a custom 'statusline'. If you're careful, you can also manipulate the
filespecs (but :DuplicateWrite needs to be invoked at least once per buffer
to set up the required autocmds).

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
DuplicateWrite-1.01.vmb.gz 1.01 2013-09-13 7.0 Ingo Karkat - FIX: Use full absolute path and normalize to be immune against changes in CWD.
- *** You need to update to ingo-library (vimscript #4433) version 1.013! ***
DuplicateWrite-1.00.vmb.gz 1.00 2013-09-13 7.0 Ingo Karkat Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo