如何阻止Vim编写文件而不会引发错误?
我正在尝试从此答案中改进代码,以在创建缺少的目录之前要求确认,这就是我写的内容: function! CreateDirectoryAskConfirmation(path) if !isdirectory(a:path) echohl Question echo "Create directory " . a:path . "?" echohl None let response = nr2char(getchar()) if response ==? "y" call mkdir(a:path, "p") endif endif endfunction autocmd BufWritePre * call CreateDirectoryAskConfirmation(expand("<afile>:p:h")) 有一件事我错过了:我不要按y在提示我想让Vim中止写,所以我没有得到错误E212: Can't open file for writing,我也不需要打另一个键,使该错误信息消失。有办法实现吗?