Solution
You can easily do with with align-regexp
, kill-rectangle
and yank-rectangle
.
Explanation
- Select the region you want to align (rows with
!!
and ||
).
- C-uM-x
align-regexp
RET
- In Complex align using regexp: field:
[|!][|!]
RET NOTE: Just append this to the auto-inserted \(\s-*\)
expression; don't replace!
- In Parenthesis group to modify..: Hit RET
- In Amount of spacing..: Hit RET
- In Repeat throughout the line? (y or n):
y
If everything went alright, you should get this (based on the original example in your question):
{| class="sortable"
! Column header (one) !! Middle column !! Last column
|-
| value 1 || loong value ... and some more || another value
|-
| some || more ||rows
|}
- Now select the region between points as shown below, between the point and mark represented by black rectangles:
{| class="sortable"
! Column header (one)▮!! Middle column !! Last column
|-
| value 1 || loong value ... and some more || another value
|-
| some || more ▮||rows
|}
- C-xrk - Kill/cut that rectangular region
- Now bring the cursor to the point where you want to move that cut rectangular region:
{| class="sortable"
! Column header (one) !! Last column ▮
|-
| value 1 || another value
|-
| some ||rows
|}
- .. and paste that area. C-xry
Result
{| class="sortable"
! Column header (one) !! Last column !! Middle column
|-
| value 1 || another value || loong value ... and some more
|-
| some ||rows || more
|}
This whole operation takes only about 10-15 seconds. So don't be discouraged by the length of this post.