I am trying to create an autocommand that will create boiler plate comments and code for new Java source files. As a simple start, I have added the following two lines (only a new line after the first line below in the actual file) to my .vim/ftplugin/java.vim:
autocmd BufNewFile *.java
\ exe "normal O/*\r" . expand('%:t') . "\t" . strftime("%B %d %Y") .
"\r/\r\rpublic class " . expand('%:t:r') . " {\r\t\<Esc>i"
With the last part, \t\<Esc>i
, I am trying to insert a tab and shift to insert mode automatically. I can't make the switch to insert mode work and have tried different permutations of two or more of \<Esc>
, \<Insert>
, "insert"
, i
and \t
. What am I missing ?
I am using VIM 7.2 on Linux.
You could use the :startinsert
command. Just execute it after the :normal
command:
autocmd! BufNewFile *.java
\ exe "normal O/*\r" . expand('%:t') . "\t" . strftime("%B %d %Y") .
\ "\r/\r\rpublic class " . expand('%:t:r') . " {\r\t" |
\ startinsert!
Here's some more information on that: http://vimdoc.sourceforge.net/htmldoc/insert.html#:startinsert.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With