Emacs: Search-n-Replace with newlines

jplindstrom on 2005-05-24T14:49:56

Today's Emacs mystery solved: How do I indicate a newline when doing Search-n-Replace with e.g. M-%

At first I tried to quote the return key by typing C-q RET, but that replaced my text with ^M.

The first colleague I asked didn't know, but then came up with the idea to enter the ASCII code in octal: C-q 012 RET, and while that worked, it seems a bit silly (and I couldn't find the ascii table in Emacs, I'm positive it's there somewhere), surely a shortcut must be available for this.

The second colleague I asked didn't know, but then came up with this one: C-q C-j. This works fine and seems to be the correct solution.

Even knowing this it wasn't easy to Google for the correct solution, but I found this nice Emacs refcard that documents this.