Thanks for the how-to. It worked. I tried it on a heading and it worked too. A nice inline implementation (rather than using a pop-up for it since we can still use autocompletion etc).
One UX idea immediately came to mind however: In addition to Return triggering a renaming, clicking a heading, making an edit, and clicking off of it (to another line) could also cause the renaming to occur. This would be closer to how we interact with headings normally, but with the added benefit that links to them are automatically being updated across our vault (and that we don’t click away and accidentally lose our edit). Escape works nicely to cancel the renaming, so it can be pressed before clicking to another line if needed. Although, special care would need to be taken when using Undo / Redo (which currently doesn’t work very well).
For example, after renaming a heading, pressing Undo will go back to the heading’s line with the old heading’s name, but Redo cannot be pressed a this stage. Now renaming the heading again will not rename it across the vault because the links to it use the edited heading, not the old heading – they’re out of sync.
The more I think about this whole concept, it seems it would take a lot to get it working just right, but at minimum, it would be great if the script could handle Undo / Redo so that the headings and links to them would remain synced. I understand Obsidian doesn’t do this either, but since your script knows were on a heading line, perhaps it could catch the Undo / Redo on it?
Nonetheless, thanks again. It’s a welcome step in the right direction.