Editing files on Google Drive

641 views
Skip to first unread message

Benjamin Fritz

unread,
Sep 15, 2014, 8:12:31 AM9/15/14
to vim_use
I recently started using Google Drive more extensively at work, and was happy to be able to edit some text files at home, hoping to see them at work later.

But when my work computer synced, it actually got a new copy of the file for every time I saved in Vim, probably due to 'backupcopy' creating a new file and renaming it rather than overwriting the old file: https://productforums.google.com/d/msg/drive/Yjmkd4nbhw4/WOhRazY3gc8J

I THOUGHT I could set 'backupcopy' in a BufRead/BufNewFile autocmd based on the location of the file I'm editing; but actually it looks like it's a global option. I want to get the benefits of "auto"/"no" documented in :help 'backupcopy' but I want to make sure my Google Drive docs get overwritten instead of copied to work around Google being careless with sync. Is there an easy way to do this? Maybe using BufEnter or BufWritePre? Will I risk bad side effects if I do that?

Bram Moolenaar

unread,
Sep 15, 2014, 8:48:25 AM9/15/14
to Benjamin Fritz, vim_use
The 'backupcopy' option should be global-local. Perhaps someone can
make a patch for that?

Can the directory tree that is under Google Drive be recognized in some
way? The we could make the "auto" value do the right thing.

--
hundred-and-one symptoms of being an internet addict:
137. You decide to stay in college for an additional year or two,
just so you can have the free Internet access.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Christian Brabandt

unread,
Sep 17, 2014, 2:00:52 PM9/17/14
to Bram Moolenaar, Benjamin Fritz, vim_use
On Mo, 15 Sep 2014, Bram Moolenaar wrote:

>
> Benjamin Fritz wrote:
>
> > I recently started using Google Drive more extensively at work, and was
> > happy to be able to edit some text files at home, hoping to see them at
> > work later.
> >
> > But when my work computer synced, it actually got a new copy of the file
> > for every time I saved in Vim, probably due to 'backupcopy' creating a new
> > file and renaming it rather than overwriting the old file:
> > https://productforums.google.com/d/msg/drive/Yjmkd4nbhw4/WOhRazY3gc8J
> >
> > I THOUGHT I could set 'backupcopy' in a BufRead/BufNewFile autocmd based on
> > the location of the file I'm editing; but actually it looks like it's a
> > global option. I want to get the benefits of "auto"/"no" documented in
> > :help 'backupcopy' but I want to make sure my Google Drive docs get
> > overwritten instead of copied to work around Google being careless with
> > sync. Is there an easy way to do this? Maybe using BufEnter or BufWritePre?
> > Will I risk bad side effects if I do that?
>
> The 'backupcopy' option should be global-local. Perhaps someone can
> make a patch for that?

I think, the attached patch does it.


Mit freundlichen Grüßen
Christian
--
Advokat, daß heißt, einer, der aus jeder Sache etwas zu machen weiß?
-- Johann Wolfgang von Goethe (zu F. J. Frommann, 1827)
bkc_global_local.diff

Ben Fritz

unread,
Sep 18, 2014, 10:52:23 AM9/18/14
to vim...@googlegroups.com, fritzo...@gmail.com
On Monday, September 15, 2014 7:48:25 AM UTC-5, Bram Moolenaar wrote:
>
> Can the directory tree that is under Google Drive be recognized in some
>
> way? The we could make the "auto" value do the right thing.
>

I don't think so, but the default seems to be "$HOME/Google Drive", at least on Windows.

I wonder if a better solution might be for me to include that directory in 'backupskip' rather than trying to mess with 'backupcopy'. I bet I could recover the file using Google Drive itself if ever Vim lost the file somehow while writing and then I don't need to mess with autocmds.

I'm not certain from the help: if I want to include subdirectories in Google Drive, would I need to do this?

set backupskip+=$HOME/Google\ Drive/**/*

Or would just this suffice?

set backupskip+=$HOME/Google\ Drive/*

Probably it still makes sense for 'backupcopy' to be global-local.

Ben Fritz

unread,
Sep 18, 2014, 11:39:05 AM9/18/14
to vim...@googlegroups.com, fritzo...@gmail.com
On Thursday, September 18, 2014 9:52:23 AM UTC-5, Ben Fritz wrote:
>
> I wonder if a better solution might be for me to include that directory in 'backupskip' rather than trying to mess with 'backupcopy'. I bet I could recover the file using Google Drive itself if ever Vim lost the file somehow while writing and then I don't need to mess with autocmds.
>
> I'm not certain from the help: if I want to include subdirectories in Google Drive, would I need to do this?
>
> set backupskip+=$HOME/Google\ Drive/**/*
>
> Or would just this suffice?
>
> set backupskip+=$HOME/Google\ Drive/*
>

Actually I needed this:

let &backupskip.=','.expand('$HOME/Google\ Drive/').'*'

And now I don't get silly duplicates, even in subdirectories.

Ben Fritz

unread,
Sep 18, 2014, 11:42:13 AM9/18/14
to vim...@googlegroups.com, fritzo...@gmail.com
On Thursday, September 18, 2014 9:52:23 AM UTC-5, Ben Fritz wrote:
>
> I wonder if a better solution might be for me to include that directory in 'backupskip' rather than trying to mess with 'backupcopy'. I bet I could recover the file using Google Drive itself if ever Vim lost the file somehow while writing and then I don't need to mess with autocmds.
>
> I'm not certain from the help: if I want to include subdirectories in Google Drive, would I need to do this?
>
> set backupskip+=$HOME/Google\ Drive/**/*
>
> Or would just this suffice?
>
> set backupskip+=$HOME/Google\ Drive/*
>

Actually I needed this:

Reply all
Reply to author
Forward
0 new messages