3

It happens that you want to save a file in a subdirectory that does not exist yet, as in

:w ~/customers/one-met-today/note.txt

when the directory one-met-today/ does not exist.

In the shell, that would be like running

mkdir "$(dirname ~/customers/one-met-today/"

before.

It would be great if multiple levels could be created, like in shell

mkdir -p "$(dirname ~/customers/one-met-today/notes/offer.txt)"

so I can do

:w ~/customers/one-met-today/notes/offer.txt

in vim.


I would prefer using an option for making :w just support that.

As alternatives:
what would be the command to solve it with shell mkdir without typing the file name twice?
Or maybe use autocmd BufWritePre and FileWritePre before :w? But that feels a little unclean, because it modifies basic behaviour in an obscure way.

Browse other questions tagged or ask your own question.