Vim: Creating parent directories on save

前端 未结 6 1823
一生所求
一生所求 2020-12-07 08:32

If I invoke vim foo/bar/somefile but foo/bar don\'t already exist, Vim refuses to save.

I know I could switch to a shell or do :!mkdi

6条回答
  •  时光说笑
    2020-12-07 09:30

    I added this to my ~/.vimrc

    cnoremap mk. !mkdir -p =expand("%:h")/

    If I need to create the directory I'm in I type :mk. and it replaces that with "!mkdir -p /path/to/my/file/" and allows me to review the command before I invoke it.

提交回复
热议问题