tags:

views:

823

answers:

2

In Emacs, I tried to replace a character say ";" with a new line using replace-string and/or replace-regexp.

Below commands are what I have tried.

M-x replace-string ; \n   (will replace ";" with 2 characters "\n" )

M-x replace-regex ; \n ( get below error from minibuffer )

Invalid use of `\' in replacement text.

Is there anything wrong using replace-string. Or if there is any other way to do that? Thanks.

+18  A: 
M-x replace-string ; C-q C-j

C-q for quoted-insert

C-j is a newline.

Cheers!

Jonathan Arkell
C-q is really `quote-insert` which quotes the next character.
Joe Casadonte
I believe it's actually "quoted" rather than "quote", as in "quoted-insert". At least that's the way it is on version 22.1.
Bryan Oakley
yes, you're right. fixed.
jrockway
Whups! Thanks guys
Jonathan Arkell
+1  A: 

Don't forget that you can always cut and paste into the minibuffer.

So you can just copy a newline character (or any string) from your buffer, then yank it when prompted for the replacement text.

It's really a good idea for the characters which I don't know the key bind.
Lei