On 08:03 Wed 12 Sep     , Ben Fritz wrote:
> On Wednesday, September 12, 2012 8:22:44 AM UTC-5, Karthick wrote:
> > Hello,
> > 
> > 
> > I would like to modify the value of 'dir' option for a few specific
> > files (e.g: all files in directory ~/Foo/). Had 'dir' been a buffer
> > local option, it would have been a easy thing,
> > au BufEnter ~/Foo/* set dir=newval
> > 
> > But 'dir' is global across buffers. Can anyone suggest workarounds?
> > 
> > 
> > I have tried
> > au BufEnter ~/Foo/* call ChangeDir()
> > au BufLeave ~/Foo/* call RevertDir()
> > 
> > function ChangeDir()
> >    let b:tmp=&dir
> >    set dir=newval
> > endfunction
> > 
> > function RevertDir()
> >    exe 'set dir=' . b:tmp
> > endfunction
> > 
> > ..but BufEnter fires *after* swap file is created.
> > 
> > If you want to know why I'm doing this - it is to prevent .swp files
> > being created in my DropBox folder (and retain default behavior in all
> > other cases)
> > 
> > -Karthick
> 
> I bet you could add BufReadPre to your BufEnter autocmd to get it to trigger 
> before swapfile creation. Maybe you'd need to add a BufReadPost to your 
> BufLeave event as well, so that the BufEnter doesn't save the wrong dir 
> option value.
> 
> I'm not sure how to make it work when you create a new file. Possibly 
> BufNewFile will work, or you can always create the document outside of Vim 
> before editing.
> 
> One workaround might be to set 'noswapfile' globally in your .vimrc, and set 
> 'swapfile' locally on BufEnter, after setting the correct 'dir' option.
> 
> Another workaround, which is probably not worth using, is that if a file is 
> loaded with 'readonly' set, Vim doesn't create a swap file until the first 
> change. You might be able to take advantage of this.

What about this idea:

function! ChangeSwap()
  let dir=&dir
  set dir=/tmp
  set swapfile!
  set swapfile!
  let &dir=dir
endfunction

au BufReadPost ../DrobBox/* :call ChangeSwap()

It is not efficient since it recreates the swap file but you could try.

Best,
Marcin




-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to