如何编写一个简单的代码段,其中占位符值在两个位置都被替换。
snippet test "test struct"
type ${1} struct {
id string
}
func (p *${1}) Id() string {
return p.id
}
endsnippet
所以当我输入test <tab>
时,它需要提示输入一个导致的值(如果我输入xyz)
type xyz struct {
id string
}
func (p *xyz) Id() string {
return p.id
}
我的系统中可能存在与其他插件的冲突,但是当我触发片段时,光标移动到第二个占位符(func (p *${1}) Id() string {
),并且永远不会完成第一个占位符。
答案 0 :(得分:2)
删除第二个{1}
周围的大括号(并且,可能会根据Ingo Karkat的指示将默认文本添加到第一个占位符):
snippet test "test struct"
type ${1:foo} struct {
id string
}
func (p *$1) Id() string {
return p.id
}
endsnippet