On 14/07/09 05:31, Matt Wozniski wrote: > > On Mon, Jul 13, 2009 at 9:45 PM, Tony Mechelynck wrote: >> >> [moving from vim_dev to vim_use] >> On 14/07/09 02:06, Toni Ruottu wrote: >>> >>> I'd be perfectly happy in doing :w! and getting the file saved under a >>> random named (like the ones you proposed) under ~/.vim/rubbish/. If >>> someone then wants to make more advanced user interfaces for exploring >>> the rubbish folder, that is fine with me too, but I'd do fine without >>> one. I don't mind tidying the files in that folder up every once in a >>> while, as long as my work is not interrupted with irritating problems, >>> like thinking of file names. >> >> Hm, after studying some parts of the help, I think it would be harder to >> implement than I thought, but I still think it could be done in >> vimscript. The question, however, is: is the game worth the candle? >> >> If you believe that thinking of a name when saving an unnamed buffer is >> too "irritating" for you to "think" of, well... >> >> Hm, here's an idea. Put this in your vimrc (untested, and, lurkers: this >> is for Unix/Linux, not Windows): > > Unless I miss something, the only part of this that is really > Unix-specific is the :!mkdir - so, why not use :call mkdir(s:savedir, > 'p') instead?
Because it wasn't at the top of my consciousnes -- but, ":help mkdir()" says "not available on all systems"; and the description uses Unix protection bits (as in numeric arguments to chmod). I suspect it doesn't work on Windows, or not the same way. Windows has "mkdir" (make directory, synonymous to "md") in command.com or cmd.exe but AFAIK it hasn't got "mkdir -p". Also, on Windows I expect ~/.vim will be replaced by ~/vimfiles, even on LFN systems where an initial period would be possible. OK, you could change that easily by "if has('unix')... else..." but as I said, this is a quickly-slopped-up example which can be made better. > >> let s:savedir = '~/.vim/rubbish' >> while !isdirectory(s:savedir) >> exe '!mkdir -p' s:savedir >> if v:shell_error >> echomsg 'Cannot create' s:savedir >> s:savedir = input('Type another path to use: ', '', 'dir') >> endif >> endwhile >> command -nargs=0 -bar -bang -complete=file -range=% W >> \<line1>,<line2>call s:Write(<q-bang>) >> function s:Write(bang) range >> try >> exe a:firstline ',' a:lastline 'w' a:bang >> catch >> exe 'w' savedir . '/' . localtime() . '.txt' >> endtry >> endfunction > > ~Matt Best regards, Tony. -- Psychotherapy is the theory that the patient will probably get well anyhow and is certainly a damn fool. -- H. L. Mencken --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---