4

I'd like to do a :wa, but save all buffers under a new path. I could to each buffer write them individually to a new path, but I'm looking to do this for all open buffers. I actually wouldn't care if all sub-paths or absolute paths were stripped, and everything was just flatly in one directory.

I'm trying to save all open vim files after deleting the directory from the shell while vim was open.

eplictical
  • 583
  • 1
  • 6
  • 16
  • 3
    I see that you have seven questions with zero accepted answers and zero votes. That is not nice. Most of users who help you like some feedback and it's how StackOverflow works. And also for those who come later to find an accepted answer to the same problem. – Birei Dec 03 '13 at 15:30
  • 1
    Thanks for pointing that out. I'll go through and accept/up-vote. The answers have definitely helped me. – eplictical Dec 03 '13 at 16:01

1 Answers1

4

All buffers calls for :bufdo. With %:t, you get the current buffer's filename (without path). Read :help filename-modifiers for all of them; you can include subpaths, too. Ergo (to make copies in /tmp/backup):

:bufdo write /tmp/backups/%:t
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • Wow! I'm getting close to restoring my project. The problem now is that many of the files were written as 0 bytes. Are these hidden buffers or something? – eplictical Dec 03 '13 at 16:48
  • `:bufdo` will cover all listed files (see `:ls`). Did you get any error messages? Do those 0-byte files actually have content inside Vim, and does the same happen when you manually `:w othername` such a file?! – Ingo Karkat Dec 03 '13 at 17:09
  • No error messages, they just generate 0-byte files. I do use [FuzzyFinder](http://www.vim.org/scripts/script.php?script_id=1984) plugin and I haven't much looked at the code for it, so perhaps it somehow loads/unloads buffers as part of its operation? – eplictical Dec 03 '13 at 18:40
  • Regarding whether the 0-byte files have contents in vim, is there a way I can find out without switching to their buffer? I tried a contrived test where I deleted the directory and switching to the buffer always produced a 0-byte file, so I don't want to check this with my real project and cause vim to try and read the file from disk. – eplictical Dec 03 '13 at 19:21
  • The 0-byte files match up with those that are not listed as active buffers in `:ls` – eplictical Dec 03 '13 at 19:26