Wednesday, September 12, 2012

Re: Changing location of swap directory for selected files, how to?

On Wednesday, September 12, 2012 10:03:09 AM UTC-5, 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,
>
> >
>
>
>
> One workaround might be to set 'noswapfile' globally in your .vimrc, and set 'swapfile' locally on BufEnter, after setting the correct 'dir' option.
>
>

I have some slow network shares, so I gave this idea a try to prevent using them for swap files. It seems successful so far, but beware of the crash I observed here: https://groups.google.com/d/topic/vim_dev/ZcJEKqNsVRI/discussion

Here's the code I came up with:

" Make slow network shares on Windows prefer not to use the file's directory
" for swap files
if has('win32')
set noswapfile
autocmd BufReadPre * setlocal noswapfile
autocmd BufEnter {Z,U,W}:{/,\\}* set dir-=. dir+=.
" nested autocmd to enable swap files so SwapExists autocmds fire, too
autocmd BufEnter * nested setlocal swapfile
autocmd BufLeave {Z,U,W}:{/,\\}* set dir-=. dir^=.
endif

--
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

No comments: