Insert by typing: Inserting a \r into vim substitution

The string in insert text works when directly typing it in Vim command mode.
But when KM is asked to insert by typing the string, the \r gets interpreted to a keystroke and vim returns -> error: pattern not found: g !

How can this be avoided ?
How can I make KM paste literal \r while pasting a string ?

Use \\r.

LOL. The editor ate part of my response, so I’ll say it this way: use double backslashes.

…and I figured out how to type it into a post. 3 backslashes and an r ends up showing 2 backslashes and an r in a post.

How far can this escapism go? :stuck_out_tongue:

Thanks Dan.

Now going through the documentation says “To include a backslash in the text, use double back slashes”. Just curious why it didn’t cause problems with \d or \s in the string but only with \r in KM.

You’re welcome.

I didn’t read the documentation - I just gave it a try. Was going to post “Have you tried…” then I thought, “well, why don’t I try it?”

I love these kinds of questions because I learn something new every time.

That field, as well as most other Text Fields in Keyboard Maestro process Tokens. Those fields also process backslashed characters \a,\b,\e,\f,\t,\r,\n (bell,backspace,escape,form feed,tab,return,line feed) (except for regular expression fields).

So \d and \s happen not to be valid characters which is why they are not altered. double slosh-s would still produce slosh-s though, because doubling the slosh would be a slosh anyway.


So, not all Actions have the options to turn off process tokens and backslash characters?
Is there a list somewhere of which Actions support this?

There are a lot of token fields, but only the Set Variable to Text action offers that facility. However I already have plans to add it to the Insert Text action. I don’t think there are other actions with a pressing need for the facility (you can always use the Set Variable to Text action and then use the variable in the field if necessary), but Insert Text is common enough that it is probably appropriate.

Any others that seem necessary?

What about the Display Text actions and Notification actions?

1 Like

The Display Text action is the same action as the Insert Text action so it will have the same options.

The Notification action seems less likely to be necessary, but more importantly it has multiple fields so it would be unclear which one the preference applies to. So probably not.

  • Added Write/Append File disable backslash or text token processing option.
  • Added Insert/Display Text disable backslash or text token processing option.
  • Added Set Clipboard to Text disable backslash or text token processing option.

Done for the next version.


Excellent. :thumbsup: Thank you very much, Peter.