On Jun 29, 7:31 pm, "Russell, Christopher A"
<[email protected]> wrote:
>
> I am open to a suggestion on how to script such a copy but, given the
> number of files I open and close on a daily basis, a manual solution
> will not work.  Remembering to do a saveas before disconnecting will not
> work either partly because of how I work but mostly because I would
> never remember to re-save them back to the network.  
>

So, do you just never save your files while you're disconnected from
your work network? I know I couldn't work that way, I'd get too
nervous about losing data. I tend to save every few minutes as I work.

That being said, this should not be too difficult to script. If I were
doing this, I'd create two commands. One to save all open buffers that
are on your network to a specified directory, and the other to restore
them. You could either enter the "save" command manually before
undocking your laptop (or at any time, really), or you could set up a
FileChangedShell autocommand to automatically call the save command
when it detects that a file no longer exists (because the network was
disconnected, presumably).

For the "save" command, I'd create a function that:
* looks at the path of the current buffer's file using expand("%:p")
* checks whether the path is on your network
* if it's on the network, save the path to a buffer-local variable
like b:original_path
* if it's on the network, do a "saveas" to the local destination
directory

I would then create a command using :command that does a "bufdo" to
call the function defined above.

The "save back to network" command would again use bufdo to call a
function, but this function would:
* check for the existence of b:original_path using exists
("b:original_path")
* if the original path exists, do a "saveas" of the buffer to the
original path using :execute "saveas ".b:original_path or similar
(escaping may be needed)
* unlet b:original_path to make sure the script doesn't get confused
in the future

To set up the autocmd to automatically call your "save locally"
command when the file no longer is available, you can take a look at
the general method here:
http://vim.wikia.com/wiki/File_no_longer_available_-_mark_buffer_modified
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to