Hi Matt!

On Mi, 02 Mär 2011, Matt Martini wrote:

> Is it possible to change the name of the swap file that Vim uses?
> 
> I have just started using a centralized location for swapfiles with the
> 'directory' option.  However, I am running into a problem of name space
> collision, or lack of same.
> 
> Often I edit files with the same name in different directories.  Vim allows
> this and has no problem creating two different swap files in the same dir.
> However, this can cause a problem in a crash.
> 
> Example:
>    1) editing /a/x.txt and /b/x.txt (directory set to .../swap)
>    2) vim creates .../swap/x.txt.swp (for /a/x.txt) 
>               and .../swap/x.txt.swo (for /b/x.txt)
>    3) normally this is fine and vim tracks which swap file is for
>       which file.
>    4) vim crash (for whatever reason)
>    5) now we try to edit /a/x.txt and vim sees x.txt.swp and prompts to
>       recover, good as expected.
>    6) We save the file and delete x.txt.swp
>    7) now we edit /b/x.txt, vim looks in .../swap and does not see
>       x.txt.swp (it does not know to look for x.txt.swo which is the
>       correct swap for the file being edited) and happily lets you
>       edit the corrupted file <-- FAIL
>    
> What I would like to do is create a function to prepend a dir "hash" to
> the name of the swap file so that even in the scenario above the files
> would have unique swap file names and this problem would be averted. 
> 
> My idea is to use the first letter of each segment of the path of the
> file prepended to the swap file name (ex: swap files from above would be
> a_x.txt.swp and b_x.txt.swp, editing /foo/bar/baz.txt would use the swap
> file fb_baz.txt.swp) While fairly simplistic this would resolve the
> problem in most cases.
> 
> Before I start wring this function, I want to know if it is even possible
> to change the name of the swap file. Also, ideally I would want to keep
> the original vim functionality of .swp .swo .swn .swm ... for reediting
> the same file.

See :h 'isdirectory' and look for the item that starts with:
- For Unix and Win32, if a directory ends in two path separators "//"

regards,
Christian
-- 

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