bsr
bsr

Reputation: 58662

UltiSnips not completing all the placeholders

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.

Upvotes: 1

Views: 243

Answers (1)

romainl
romainl

Reputation: 196566

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

Upvotes: 2

Related Questions