diff --git a/misc.vim b/misc.vim new file mode 100644 index 0000000..f3c48fe --- /dev/null +++ b/misc.vim @@ -0,0 +1,21 @@ +func s:mdxUpdateDate() + " guard --- + if getline(1) != "---" | return | endif + " find end --- + let lineEnd = search('\v%>1l^---$', 'n') + if lineEnd == 0 | return | endif + " prepare + let now = strftime('%Y/%m/%d(%a) %H:%M:%S') + let patpfx = '\v%>1l%<'.lineEnd.'l' + " createdAt + let line = search(patpfx.'^createdAt:\s*$', 'n') + if line > 0 | call setline(line, 'createdAt: '.now) | endif + " createdAt + let line = search(patpfx.'^updatedAt:', 'n') + if line > 0 | call setline(line, 'updatedAt: '.now) | endif +endfunc + +augroup sup39_vimrc_misc + au! + au BufWritePre *.mdx call mdxUpdateDate() +augroup END