diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-05-30 00:42:27 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-05-30 00:42:27 +1200 |
commit | 53f1a5c423af025ea02ad3ee92099100994b8cb9 (patch) | |
tree | 86a4882170aeae47d9d8f4bc05e84b0f8337b7ef | |
download | vim-write-mkpath-53f1a5c423af025ea02ad3ee92099100994b8cb9.tar.gz vim-write-mkpath-53f1a5c423af025ea02ad3ee92099100994b8cb9.zip |
First versionv0.1.0
-rw-r--r-- | README.md | 13 | ||||
-rw-r--r-- | VERSION | 1 | ||||
-rw-r--r-- | autoload/write_mkpath.vim | 5 | ||||
-rw-r--r-- | doc/write_mkpath.txt | 20 | ||||
-rw-r--r-- | plugin/write_mkpath.vim | 17 |
5 files changed, 56 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..aefaaa4 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +write\_mkpath.vim +================= + +If `:write!` is issued for a file that has nonexistent path elements, create +the full path with `mkdir()` before saving. + +License +------- + +Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself. +See `:help license`. + +[1]: https://sanctum.geek.nz/ @@ -0,0 +1 @@ +0.1.0 diff --git a/autoload/write_mkpath.vim b/autoload/write_mkpath.vim new file mode 100644 index 0000000..36d3501 --- /dev/null +++ b/autoload/write_mkpath.vim @@ -0,0 +1,5 @@ +function! write_mkpath#(path) abort + if v:cmdbang && !isdirectory(a:path) + call mkdir(a:path, 'p') + endif +endfunction diff --git a/doc/write_mkpath.txt b/doc/write_mkpath.txt new file mode 100644 index 0000000..8d7bcc2 --- /dev/null +++ b/doc/write_mkpath.txt @@ -0,0 +1,20 @@ +*write_mkpath.txt* For Vim version 7.0 Last change: 2019 May 28 + +DESCRIPTION *write_mkpath* + +If |:write!| is issued for a file that has nonexistent path elements, create +the full path with |mkdir()| before saving. + +REQUIREMENTS *write_mkpath-requirements* + +This plugin only loads if 'compatible' is not set. + +AUTHOR *write_mkpath-author* + +Written and maintained by Tom Ryder <tom@sanctum.geek.nz>. + +LICENSE *write_mkpath-license* + +Licensed for distribution under the same terms as Vim itself (see |license|). + + vim:tw=78:ts=8:ft=help:norl: diff --git a/plugin/write_mkpath.vim b/plugin/write_mkpath.vim new file mode 100644 index 0000000..4a47d70 --- /dev/null +++ b/plugin/write_mkpath.vim @@ -0,0 +1,17 @@ +" +" write_mkpath: If :write! is issued for a file that has nonexistent path +" elements, create the full path with mkdir() before saving. +" +" Author: Tom Ryder <tom@sanctum.geek.nz> +" License: Same as Vim itself +" +if exists('loaded_write_mkpath') || &compatible || v:version < 700 + finish +endif + +" Check path to every file before it's saved +augroup write_mkpath + autocmd! + autocmd BufWritePre * + \ call write_mkpath#(expand('<afile>:p:h')) +augroup END |