Set keys for find/replace to prevent duplicate keys

Fixes #5168