Abstract out the search and replace functionality.

This is in preparation for adding the `tabify` command.