27

I have the a string like this (separtred by asterisk) :

abc*dddd*fffff*

i need to replace the * with a newline. i.e the result should be:

abc
dddd
fffff

How can I do this in Emacs? I tried query-replace but pressing enter doesn't do what I want.

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
AKM
  • 6,285
  • 9
  • 31
  • 34

2 Answers2

48

Do quote the enter key: C-q C-j. There, C-q inserts the next key literally and C-j gives newline.

maxelost
  • 1,517
  • 11
  • 12
  • `C-j` produces ASCII 0x0a (\n, newline, linefeed). The ENTER key produces 0x0d (\r, carriage-return). Anyone who knows the background for this? – maxelost Feb 01 '11 at 11:21
  • Historically, control keys were represented (over serial terminals and other byte-stream protocols) as `^A` = 1, `^B` = 2, and so on. And so `^J` is 10. ENTER was (arbitrarily? I don't know) the same as `^M`, or 13. – nelhage Feb 02 '11 at 05:35
  • 1
    Old post, but the key you are calling ENTER is actually called the carriage return key, while the ENTER key is the one on the numeric key pad. – Sardtok Aug 05 '15 at 07:16
12

Try query-replace   enter   *   enter   M-j   enter    !   enter

sbaker
  • 398
  • 1
  • 8