Thursday, February 6, 2014

Re: Adding a file name to a template

> I would like to know if I can put the file name into the template
> automatically. This is what I have in my .vimrc to create the
> template:
>
> augroup filetype_html
> autocmd!
> autocmd BufNewFile * silent! 0r $HOME/.vim/templates/%:e.tpl
> augroup END


Try defining the autocmd as:

autocmd BufNewFile * silent! 0r $HOME/.vim/templates/%:e.tpl | exe "normal! ggA " . expand("%")

Or, to make things a bit safer, use this function:

function! LoadTemplate ()
let [fi, sk] = [expand("%"), expand("$HOME/.vim/templates/") . expand("%:e") . ".tpl"]
if filereadable(sk)
exe "silent 0r " . sk
exe "normal! ggA " . fi
endif
endfunction

Best,
Paul

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment