Closed lilx2018 closed 1 year ago
I find Rg support to filter by filename but often priority is too low which not on show.
Yeah, a trick would be to append :
to your search query. e.g. pathfragment:
, pathfragment:contentfragment
.
I modify the source code a little to let the filename of highest priority of scores.
src\algo\algo.go, func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input util.Chars, pattern []rune, withPos bool, slab util.Slab) (Result, *[]int) { ...
// -------------------- Lilx, add code start -------------------------
str := input.ToString()
p1 := strings.LastIndex(str, "\\")
if p1 < 0 {
p1 = strings.LastIndex(str, "/")
}
p2 := strings.Index(str, ":")
if p2 > p1+1 && strings.Index(str[p1+1:p2], string(pattern)) == 0 {
maxScore += 1000
} else if p1 >= 0 && strings.Index(str[p1+1:], string(pattern)) == 0 {
maxScore += 1000
}
// -------------------- Lilx, add code end -------------------------
// Start offset we return here is only relevant when begin tiebreak is used.
// However finding the accurate offset requires backtracking, and we don't
// want to pay extra cost for the option that has lost its importance.
return Result{j, maxScorePos + 1, int(maxScore)}, pos
}
man fzf
)I use Rg command to search word in files, after search done, then I will continue hit some keys to narrow down candidates from too many files. I hope it can filter by specifying the filename, but Rg command seem only support to filter by text line, not support to filter by filename.