Vim: Add two lines after auto shebang

Viewed 219

I have set my .vimrc to automatically add a shebang line, as below:

autocmd BufNewFile * execute 'silent! 1s/.*/#!\/usr\/bin\/env ' . (empty(&filetype) ? '' : ' '.&filetype)

However, I would like it to also add two lines below it and go into insert mode. When I simply add $i to the end of the command, as below, I get an error. Ideas?

autocmd BufNewFile * execute 'silent! 1s/.*/#!\/usr\/bin\/env ' . (empty(&filetype) ? '' : ' '.&filetype) $<CR><CR>i
1 Answers

You can use this:

autocmd BufNewFile * if !empty(&filetype) | execute 'silent! 1s/.*/#!\/usr\/bin\/' . &filetype . '\r\r'| :startinsert | endif

Btw, neat thinking, I'm adding this to my vimrc :)

Related