October 2015
Intermediate to advanced
356 pages
7h 54m
English
| Tip 45 | Save Files to Nonexistent Directories |
Vim is happy to let us edit a buffer whose path includes directories that don’t exist. It’s only when we attempt to write the buffer to a file that Vim objects. Here’s a quick tip on how to deal with this situation.
The :edit {file} command is most commonly used to open a file that already exists. But if we specify a filepath that doesn’t correspond to an existing file, then Vim will create a new empty buffer. If we press <C-g>, we’ll see that the buffer is labeled as “new file” (the <C-g> command echoes the name and status of the current file; see ctrl-Gⓘ). When we run the :write command, Vim will attempt to write the contents of that buffer to a new file using the filepath that was specified when ...