Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
    
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 –  warl0ck Mar 27 '13 at 8:27
    
:help startinsert –  Sukminder 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

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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