3

Still related to the previous question, but switching mode with exe "a" doesn't seem to work, I still have to press the a button manually

Here upon opening a newly created a file, a template is in use and the cursor will be moved to the right position, then erase the tag, and switch to the appending (editing) mode.

function LoadFile()
  0r ~/.vim/skel/tmpl.%:e
  exe "normal /<CURSOR>\<Cr>"
  exe "s#<CURSOR>##"
  exe "a"
endf

autocmd! BufNewFile * silent! call LoadFile()

Any ideas?

  • You might want to link to "the previous question" so it is clear what you are refrring to (if it is relevant to this question)... – jasonwryan Mar 27 '13 at 8:12
  • @jasonwryan added – daisy Mar 27 '13 at 8:27
  • :help startinsert – Runium Mar 27 '13 at 9:08
  • Add d% ot df> after the \<Cr> there. You don't need exe for the other ones mine was just to expand \<Cr>. I'm not sure it's even necessary there. – Stéphane Chazelas Mar 27 '13 at 9:53
3

First, that would be :normal! a instead of :exe "a"; this is a normal-mode command.

Second, for implementation reasons, that does not work; you have to use the special :startinsert! command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.