Sublime Text plugin to modify text before it's pasted
If your intention is to escape certain characters by prefixing them with backslashes, you would be better off with a function that performs that specific task, rather than a generalized function that accepts a dictionary of replacements.

In general, performing multiple substitution passes over a string is a bad idea.  Certain substitution dictionaries could result in non-deterministic behaviour, depending on the order in which the substitutions are performed.  In fact, you have just that problem:


If the _ escape is performed before the \ escape, then _ would become \_, then \\_.
If the \ escape is performed before the _ escape, then _ would remain _, then become \_.


You could overcome that problem by specifying the substitutions using a collections.OrderedDict, but I still recommend against it on principle.  Escaping / unescaping is always better done using a single left-to-right pass.