Solution
There is an easy solution to your updated question too, but you will need to install the Multiple Cursors package, also available through Melpa.
Step 1. Kill/cut the rectangle (same as before)
▮= 1
= 2
= 3
= 4▮
- Select the region shown above between the two points.
C-x r k
- Kill/cut that rectangular region between the two points.
Step 2. Yank the just killed rectangle to the location of your choice
const int someName ▮
const int anotherName
const int yetAnotherName
const int name
- Bring the point at the above shown location
- Note that this location needs to be at any point in the column that's not occupied by any of the below lines. If you can imagine a vertical line closest to the left which does not cut any of those 4 lines, bring the point to the right of that line.
C-x r y
- Yank/paste the killed rectangle
That will result in the below
const int someName = 1▮
const int anotherName = 2
const int yetAnotherName = 3
const int name = 4
- Now we need to remove that extra spaces between the variable names the
=
signs.
Step 3. Removing extra space
For this step, first bring the point over the first =
sign as shown below (the point is hiding the =
sign beneath it).
const int someName ▮ 1
const int anotherName = 2
const int yetAnotherName = 3
const int name = 4
- Create Multiple Cursors at all
=
signs: M-3 C->
. C->
is bound to mc/mark-next-like-this
.
That will give you this; the =
signs are still hidden beneath the cursors.
const int someName ▮ 1
const int anotherName ▮ 2
const int yetAnotherName ▮ 3
const int name ▮ 4
C-SPC M-b M-f BKSPACE SPC RET
- Delete any space between the multiple cursors and the words before them and instead insert a single space.
Result
const int someName = 1
const int anotherName = 2
const int yetAnotherName = 3
const int name = 4
Older answer
Using rectangle
is the first thing that comes to my mind.
Step 1. Kill/cut the rectangle
▮= 1
= 2
= 3
= 4▮
- Select the region shown above between the two points.
C-x r k
- Kill/cut that rectangular region between the two points.
Step 2. Yank the just killed rectangle to the location of your choice
const int name1 ▮
const int name2
const int name3
const int name4
- Bring the point at the above shown location
C-x r y
- Yank/paste the killed rectangle
Result
const int name1 = 1
const int name2 = 2
const int name3 = 3
const int name4 = 4
Learning