[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): 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 Then use :W instead of :w (when with no arguments). When there are arguments you should still use :w in lowercase. But you can use :W! instead of :w! if you want to. If I didn't goof, this should write the current buffer under its own name if possible, and if not, it writes it to some rubbish directory as a .txt file with the time in seconds since 1970 as its name -- IOW, it assumes that you won't save more than one "unnamed" buffer per second. The top "while" loop is to make sure that the rubbish directory exists -- if it doesn't and can't be created, you're asked for another name. In that case, modify your vimrc so you aren't asked at every startup. This is just a quick solution I slopped up without too much hardship. I think it can be made better, and that it shouldn't be too hard -- after all, Vim is extremely well documented. If this doesn't do all that you need, well, "the solution is left as an exercise to the reader", then. I'm moving this to the vim_use group (or trying to) since it's become a question about "using" Vim, not a question about "changing the C code" of Vim. Best regards, Tony. -- Sex is not the answer. Sex is the question. "Yes" is the answer. -- Swami X --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---