Paste mode from autocmd to Vim

I am trying to create an auto team that will create comments and boiler room code for the new Java source files. As a simple start, I 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" 

In the last part of \t\<Esc>i I try to insert a tab and automatically switch to insert mode. I cannot get the switch to work in insert mode 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 for Linux.

+4
source share
1 answer

You can use the command :startinsert . Just execute it after the command :normal :

 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 more info on this: http://vimdoc.sourceforge.net/htmldoc/insert.html#:startinsert .

+13
source

All Articles