I am writing a rudimentary Vim template for Java files that creates a bare skeleton class when I create a new file with the .java extension.
Example:
vim Banana.java
Vim creates a file including code like this:
public class TODO {
public static void main(String[] args) {
// ...
My objective is to change my default class name, TODO
, to the name of the file without the extension so that:
vim Coconut.java
creates:
public class Coconut {
rather than:
public class TODO {
How can I achieve that, please? I have searched the site and there are scripts that extract the name in a variable and perform :substitute in the right place, but I don't know how to locate the right place and position the filename there.
I read my template files by extension from my .vimrc:
autocmd BufNewFile * silent! 0r $HOME/vimfiles/templates/%:e.vim_template
or:
autocmd BufNewFile * silent! 0r $HOME/.vim/templates/%:e.vim_template
Thanks!