junegunn/fzf · error

template should include at least 1 placeholder: ${str}

Error message

template should include at least 1 placeholder: ${str}

What it means

nthTransformer accepts either a plain range list or a template containing placeholders like {1}, {2..5}, {n}, or {..3}. If the --nth argument is neither (contains no {…} placeholder at all), this error demands at least one placeholder. It fires after the plain-range branch was already ruled out.

Source

Thrown at src/options.go:875

func nthTransformer(str string) (func(Delimiter) func([]Token, int32) string, error) {
	// ^[0-9,-.]+$"
	if match, _ := regexp.MatchString("^[0-9,-.]+$", str); match {
		nth, err := splitNth(str)
		if err != nil {
			return nil, err
		}
		return func(Delimiter) func([]Token, int32) string {
			return func(tokens []Token, index int32) string {
				return JoinTokens(Transform(tokens, nth))
			}
		}, nil
	}

	// {...} {...} ...
	placeholder := regexp.MustCompile("{[0-9,-.]+}|{n}")
	indexes := placeholder.FindAllStringIndex(str, -1)
	if indexes == nil {
		return nil, errors.New("template should include at least 1 placeholder: " + str)
	}

	type NthParts struct {
		str   string
		index bool
		nth   []Range
	}

	parts := make([]NthParts, 0, len(indexes))
	idx := 0
	for _, index := range indexes {
		if idx < index[0] {
			parts = append(parts, NthParts{str: str[idx:index[0]]})
		}
		expr := str[index[0]+1 : index[1]-1]
		if expr == "n" {
			parts = append(parts, NthParts{index: true})
		} else if nth, err := splitNth(expr); err == nil {

View on GitHub (pinned to bd4efa277b)

Solutions

  1. Inside {} placeholders use '..' ranges, not '-': --nth {1..3},7
  2. Ensure at least one placeholder exists: append {n} if you want all fields
  3. Use the comma-separated plain form without braces when templates are not needed

Example fix

# before
fzf --nth '{1-3},7'
# after
fzf --nth '{1..3},7'
Defensive patterns

Strategy: validation

Validate before calling

NTH='{1..3},7'
grep -Eq '\{([0-9,-]+\.\.[0-9,-]*|[0-9,-]+|n)\}' <<< "$NTH" || { echo 'nth template lacks a {..} placeholder' >&2; exit 1; }
fzf --nth "$NTH"

Prevention

When it happens

Trigger: Passing --nth '{ }' (space inside braces, so regex {[0-9,-.]+}|{n} misses it), --nth '{}', --nth 'field{n}' is OK but --nth 'field' (forgot the placeholder) fails, --nth '{1-2}' with a single hyphen (regex only matches '..' ranges inside braces) also fails the placeholder match.

Common situations: Users writing {1-3} instead of {1..3} in template mode; forgetting the {n} placeholder in joiner templates; using single-hyphen ranges in both --nth forms out of habit from other tools.

Related errors


AI-assisted analysis of junegunn/fzf@bd4efa277b (2026-08-15). Data as JSON: /api/errors/83a71198c5b9bc9d. Report an issue: GitHub.