├── README.md └── plugin └── mkdir.vim /README.md: -------------------------------------------------------------------------------- 1 | > [!NOTE] 2 | > All of my GitHub repositories have been **archived** and will be migrated to 3 | > Codeberg as I next work on them. This repository either now lives, or will 4 | > live, at: 5 | > 6 | > https://codeberg.org/pbrisbin/vim-mkdir 7 | > 8 | > If you need to report an Issue or raise a PR, and this migration hasn't 9 | > happened yet, send an email to me@pbrisbin.com. 10 | 11 | # Mkdir 12 | 13 | > Maggie! Don't even ask. Just bring it. Come on. 14 | 15 | *-- Hot Rod* 16 | 17 | ## Installation 18 | 19 | Add `pbrisbin/vim-mkdir` to your preferred [vim plugin management plugin](https://linuxhandbook.com/install-vim-plugins/) list. 20 | 21 | I happen to use lua configuration and [minpac](https://github.com/k-takata/minpac), so my `~/.config/nvim/init.lua` contains, 22 | 23 | ```lua 24 | vim.cmd [[ packadd minpac ]] 25 | 26 | vim.call('minpac#init') 27 | vim.call('minpac#add', 'pbrisbin/vim-mkdir') 28 | ``` 29 | 30 | ## Usage 31 | 32 | ``` 33 | :e this/does/not/exist/file.txt 34 | :w 35 | ``` 36 | 37 | Smile when you are not presented with an error. Instead, notice that 38 | vim has automatically created the non-existent directory for you. 39 | -------------------------------------------------------------------------------- /plugin/mkdir.vim: -------------------------------------------------------------------------------- 1 | if exists("g:mkdir_loaded") 2 | finish 3 | endif 4 | 5 | let g:mkdir_loaded = 1 6 | 7 | function s:Mkdir() 8 | let dir = expand('%:p:h') 9 | 10 | if dir =~ '://' 11 | return 12 | endif 13 | 14 | if !isdirectory(dir) 15 | call mkdir(dir, 'p') 16 | echo 'Created non-existing directory: '.dir 17 | endif 18 | endfunction 19 | 20 | autocmd BufWritePre * call s:Mkdir() 21 | --------------------------------------------------------------------------------