add: auto cmd for create folder and file

This commit is contained in:
asep komarudin 2024-03-05 23:18:08 +07:00
parent 73fb95878b
commit f99a244c36
3 changed files with 29 additions and 2 deletions

View file

@ -16,3 +16,18 @@ local term_program = vim.fn.getenv("TERM_PROGRAM")
if term_program == "WezTerm" then
vim.cmd('silent !wezterm cli set-tab-title "' .. _get_folder_name() .. '"')
end
-- vim.cmd([[
-- function s:MkNonExDir(file, buf)
-- if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/'
-- let dir=fnamemodify(a:file, ':h')
-- if !isdirectory(dir)
-- call mkdir(dir, 'p')
-- endif
-- endif
-- endfunction
-- augroup BWCCreateDir
-- autocmd!
-- autocmd BufWritePre * :call s:MkNonExDir(expand('<afile>'), +expand('<abuf>'))
-- augroup END
-- ]])

View file

@ -43,6 +43,19 @@ vim.cmd([[
" allows you to use Ctrl-c on terminal window
autocmd TermOpen * nnoremap <buffer> <C-c> i<C-c>
augroup END
function s:MkNonExDir(file, buf)
if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/'
let dir=fnamemodify(a:file, ':h')
if !isdirectory(dir)
call mkdir(dir, 'p')
endif
endif
endfunction
augroup BWCCreateDir
autocmd!
autocmd BufWritePre * :call s:MkNonExDir(expand('<afile>'), +expand('<abuf>'))
augroup END
]])
-- for fix error last close buffer