1

I have a piece of code like this in yaml.

security_group_sig_egress_ipv6: "allowed_remote_sig_egress_ipv6"
security_group_sig_ingress_ipv6: "allowed_remote_sig_ingress_ipv6"
security_group_int_egress_ipv4: "allowed_remote_int_egress_ipv4"
security_group_int_ingress_ipv4: "allowed_remote_int_ingress_ipv4"
security_group_int_egress_ipv6: "allowed_remote_int_egress_ipv6"
security_group_int_ingress_ipv6: "allowed_remote_int_ingress_ipv6"
security_group_om_egress_ipv4: "allowed_remote_om_egress_ipv4"
security_group_om_ingress_ipv4: "allowed_remote_om_ingress_ipv4"
security_group_om_egress_ipv6: "allowed_remote_om_egress_ipv6"
security_group_om_ingress_ipv6: "allowed_remote_om_ingress_ipv6"

as you can see the ":" is the delimiter between the two expressions. I want to transpose/swap the "key:value" pair in following way for the entire rectangular region:

allowed_remotexxxx: "security_groupxxx"
allowed_remotexxxx: "security_groupxxx"
allowed_remotexxxx: "security_groupxxx"
allowed_remotexxxx: "security_groupxxx"

I can use Anchored Transpose to transpose each line separately but not the whole rectangular region. Is there a way in Emacs to achieve this with minimum keystrokes?

1
  • Using a keyboard macro comes to mind.
    – Drew
    Commented Sep 15, 2017 at 16:16

2 Answers 2

2

Multiple cursors works well for these things. You can select : " and then invoke mc/mark-all-like-this.

Here's a demo for your use-case

0
1

You can use replace-regexp with the following patterns:

Replace 2 groups of characters separated by colon, space and quotes:

 ^\(.*\):\ "\(.*\)"$

With the capture groups swapped and reformatted:

\2: "\1"
1
  • Thanks for the tip. Can I run all these commands under a rectangular mark?
    – Black_Zero
    Commented Sep 18, 2017 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.