I have a file template which is rendered with replacing some stubs when new file created:
augroup templates
autocmd!
autocmd BufNewFile *.java $r ~/.vim/templates/skeleton.java|call s:SetupJavaClass()
fun! s:SetupJavaClass()
exe "%s/__CLASS_NAME__/" . expand('%:t:r')
endfun
augroup END
it's working fine, but only if I create new file with new buffer, e.g. vim Foo.java
works, but when I create new file from NerdTree, new file is opening in current buffer and my templates and vim doesn't call my autocommands. How can I fix it? Is it possible to create autocommand to be executed on every new file, doesn't matter it was opened in new buffer or not, or maybe I should use ftplugin for that?
m
, thena
to add new file, then I type filename, it creates a file which I'm opening in current buffet witho
key.(a)dd a childnode
menu item will ultimately result in a call towritefile([], a:fullpath)
insidenerdtree/lib/nerdtree/path.vim
. I don't think there is an autocommand that is triggered bywritefile()
. You might want to ask the maintainer of NerdTree if he/she could provide a hook for reading a template file.