<Tab> 从函数中按键进入缓冲区

<Tab> keypress into buffer from function

我正在努力创建一个函数,它将:

到目前为止,除了触发 snipmate 之外,我的一切正常。我想做的是插入一个 <Tab> 字符,就像我在插入模式下一样,以触发 snipmate 启动

" 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

相反,它实际上是映射到 test<Tab> 到我的模板中。我的猜测是我不想为此使用 norm,但我不太热衷于应该使用什么。

有什么想法吗?

有没有办法从函数进入插入模式?

:normal之后的一切按字面意思处理;插入特殊字符,需要用双引号:execute来计算:

execute "norm i test\<Tab>"

对于制表键,您也可以写成 "\t";不过,:help key-notation 是更常见和通用的一种。