2011-08-07 65 views
4

我想創建一個自動命令,它將爲新的Java源文件創建鍋爐板評論和代碼。作爲一個簡單的開始,我有以下兩行(僅低於實際文件的第一行後,新行)添加到我的.vim /文件類型插件/ java.vim裏:從autocmd插入模式在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" 

隨着最後一部分, \t\<Esc>i,我試圖插入一個選項卡並自動切換到插入模式。我不能使開關插入模式工作,並嘗試了\<Esc>,\<Insert>,"insert",i\t中的兩個或多個的不同排列。我錯過了什麼? 我在Linux上使用VIM 7.2。

回答

13

您可以使用:startinsert命令。在: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! 

這裏有一些更多信息:http://vimdoc.sourceforge.net/htmldoc/insert.html#:startinsert