I am using a plugin that expands the word template by a template but only if the word template is followed by a tab. I am trying to write the word new then in insert mode jump to the end of the line then insert the tab, I am on mac too. When I try this command from command mode in vim, it works but when I try it in a vim script it doesn't work. What am I doing wrong?

let longstring = substitute('template','','\r','i')
call writefile(['template'], l:new, '')
augroup templates
execute "split"
execute ":normal! A^I;"
execute ":e!" . l:new
augroup END

EDIT: This is the command that works: > execute ":normal! A^I;" I am using the UltiSnips, the word needs to be followed by the tab character to kick off the template.

  • Welcome to Vi and Vim! Sorry, but it's really hard to understand what you're doing here, and also hard to understand what you're trying to accomplish. The snippet you pasted is using an augroup but all that does is group autocmds together and you have none of them. You're using this l:new variable that you didn't definite anywhere... It's hard to understand the task itself... You talk about this plug-in that expands the word template, is it the word "template" itself? Which plug-in is the one you're using?
    – filbranden
    Jan 3 at 17:53
  • Which is the command that works when you try it from command mode? What does it do when it works? What happens when it doesn't work? Please edit your question and add a lot more details here, otherwise it'll be hard to figure out how to help you here...
    – filbranden
    Jan 3 at 17:55
  • I have edited to answer your questions Jan 3 at 20:42
  • 2
    Try using \<tab> instead of ^I.
    – Heptite
    Jan 3 at 21:56
  • \<tab> doesn't work either Jan 4 at 0:02

Your Answer

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

Browse other questions tagged or ask your own question.