1

Suppose I have the following text:

:lacerte-attach-statement-type "suffix" :data-automation-id "OSICtrlE15-140"

And I would like to have:

:data-automation-id "OSICtrlE15-140" :lacerte-attach-statement-type "suffix" 

Of course, I can kill :data-automation-id "OSICtrlE15-140" and then yank it first on the line (column 0).

But, is there a more efficient way? Like transposing the pair of words?

I tried the command called transpose-region after selecting the first pair as a region but it did not work out.

Pedro Delfino
  • 1,369
  • 3
  • 13
  • 3
    I don't know if it's the most efficient, but `transpose-region` works if you think about how the mark gets pushed to the `mark-ring`. Try this with point at column 0: `C-SPC C-M-f C-M-f C-SPC C-f C-SPC C-e M-x transpose-region` Note that when you press C-SPC, you aren't pushing the current point onto the `mark-ring`, you're pushing the current *mark* (if there is one) onto the `mark-ring`. – mmarshall540 Jan 19 '23 at 01:57

1 Answers1

6

Some observations first. When asking a question like that you must refer the mode, because the concept of a word depends on the major mode (lookup syntax tables in Elisp documentation). In this case, it is wiser to navigate and transpose sexps, not words.

Assuming that the point is located where the mark "|" is, :lacerte-attach-statement-type "suffix"| :data-automation-id "OSICtrlE15-140", you could run the following:

(progn
  (transpose-sexps 2)
  (backward-sexp 3)
  (transpose-sexps 2))

Using the default keybindings, it could be done interactively with the following combo: C-M-2 C-M-t C-M-3 C-M-b C-M-2 C-M-t. Notice that can keep the Control and Meta keys pressed down the whole time.

aadcg
  • 1,203
  • 6
  • 13
nichijou
  • 1,158
  • 10
  • 14