Quite often you may find yourself editing a file in a nonexistent directory.
If you’re a Rails developer, you may have used:
This creates the show page for the current controller you’re working on, however the app/views/controller directory may not exist yet, and Vim will not let you save a file in a nonexistent directory. So this what you do:
:h expand to the see the meaning of the modifiers used if you’re interested.
An aside, this is what I previously used:
This has the benefit of prompting of me when I try to save a file in
non-existent directory. However, I feel like the less configuration I have to
rely on the better, and also,
:!mkdir %:p:% feels, and looks much more