0

I have a list that looks like

1.530 2.895
4.362 50.14
3.14  2.7

And I want it to look like

1.530
2.895
4.362
50.14
3.14
2.7 

I suspect there is a clever way to use a rectangle to do this but I cannot figure it out.

  • Why using a rectangle? This is simply replacing spaces by linebreaks. I.e., C-M-% [ <SPACE> ] + <RET> C-j <RET>... The key sequence for (query-replace-regexp "[ ]+" "\n") – Tobias Nov 22 '16 at 16:28
  • @Tobias thanks for that, I just tried it but it did not seem to work. I think it did not register when i hit C-j because it simply removed the space – Jaime Arturo Gomez Nov 22 '16 at 16:34
  • Sorry, you have to type C-q C-j instead of only C-j. C-q causes literal insertion of the next keystroke. – Tobias Nov 22 '16 at 16:35
  • I wrote up an answer to mark this question in the question list as answered. – Tobias Nov 22 '16 at 16:50
2

You don't need a rectangle for this job. Just use (query-replace-regexp "[ ]+" "\n") to replace the separating spaces by linebreaks. The corresponding key-sequence is:

C-M-% [ ]+ RET C-q C-j RET

Meaning:

  • C-M-% query-replace-regexp
  • [ ]+ the regular expression for the strings to be replaced (one or more spaces)
  • C-q next character is inserted literally (quoted-insert)
  • C-j newline as the only character of the replacement string
  • Note the square brackets are not necessary here: they define a "character alternative" with space as the only choice, so you can just use a space followed by a +. – JeanPierre Nov 22 '16 at 18:56

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.