1

How to write a simple snippet where the placeholder value is replaced at both places.

snippet test "test struct" 
type ${1} struct {
    id string
}

func (p *${1}) Id() string {
    return p.id
}

endsnippet

so when I type test<tab>, it needs to prompt for entering one value which results in (if I enter xyz)

type xyz struct {
        id string
    }

    func (p *xyz) Id() string {
        return p.id
    }

there could be a conflict with other plugins in my system, but currently when I trigger the snippet, cursor moves to second placeholder (at func (p *${1}) Id() string {), and never completes the first one.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
bsr
  • 57,282
  • 86
  • 216
  • 316

1 Answers1

2

Remove the braces around the second {1} (and, maybe, add default text to the first placeholder as pointed out by Ingo Karkat):

snippet test "test struct" 
type ${1:foo} struct {
    id string
}

func (p *$1) Id() string {
    return p.id
}

endsnippet
romainl
  • 186,200
  • 21
  • 280
  • 313