2

I'm working on creating a function that will:

  • Inspect the current file I'm working on
  • Create a new buffer in my test directory based on my file name
  • Edit that file and start my snipmate "test" template

So far I have everything working except triggering snipmate. What I'd like to do is insert a <Tab> character like I was in insert mode to trigger snipmate to kick off

" Only works for modules and models right now
function! MakeTest()
  " sub out any prefix
  let base_test_path = substitute(expand('%:r'), '\(lib/\|app/models/\)', '', 'g')
  execute 'edit ' . 'test/unit/' . base_test_path . '_test.rb'
  norm i test<Tab>
endfunction

Instead it is literally mapping to test<Tab> into my template. My guess is that I don't want to use norm for this, but I'm not too keen on what I should use instead.

Any thoughts?

Is there a way to enter insert mode from a function?

Josh Bodah
  • 1,223
  • 6
  • 17

1 Answers1

1

Everything after :normal is treated literally; to insert special characters, you need to use double quotes and :execute to evaluate them:

execute "norm i test\<Tab>"

For the tab key, you could have alternatively written "\t"; the :help key-notation is the more common and general one, though.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324