0

I want a register to contain backslashes, but when I try they get removed. Example (for
"first_name last_name" → "last_name, first name" in a file with all lines according to regex pattern:
/^[^ \n]+ [^ \n]+$/gm):

  1. Setting register 1 with let:
    :let @1="%s/\(.*\) \(.*\)/\2, \1/g"
  2. Displaying register 1 (inserted at the current line):
    :put 1
  3. The insertion:
    "%s/(.*) (.*)/^B, ^A/g"

I want that register to contain backslashes so that it can be executes as a command in command mode.

Community
  • 1
  • 1
Rublacava
  • 414
  • 1
  • 4
  • 16

1 Answers1

0

Fix (escape the escapes):

:let @1="%s/\\(.*\\) \\(.*\\)/\\2, \\1/g"
Rublacava
  • 414
  • 1
  • 4
  • 16