0

I have column of text like this:

Abba
Foo
Boo
M

and I want to transform it to:

Abba = Abba
Foo = Foo
Boo = Boo
M = M

I can add " = " to end column of text via C-x space and M-x string-insert-rectangle, also I can copy column via vertical selection C-x space, but how I paste column to the right of another column?

  • With Magnar's multiple-cursors library you can place a cursor at the beginning all lines in a selected region; then you can hold down the shift key and the alt key and move the arrow once to the right (which will select the word on each line; then you can hit the copy command (which should also deselect the region, if not then press C-g one time); then hit the space bar, type an = sign, then hit the space bar, and yank/paste. At this point you are done, and just hit the enter key to exit. – lawlist Sep 13 '18 at 19:21
  • 1
    The easiest way to do this with vanilla Emacs would be to use a macro. – DoMiNeLa10 Sep 13 '18 at 20:27
2

You don't really want to use rectangles for this, because the desired end result is not aligned as rectangles.

Either use a keyboard macro. e.g.:

  • <f3> - start recording
  • C-kC-ySPC=SPCC-y - transform the first line
  • <right><f4> - move to the next line, and stop recording
  • <f4><f4><f4> - replay for the remaining lines

Or query-replace-regexp:

C-M-% .* RET \& = \& RET

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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