How to replace a character with a newline in Emacs?

I am trying to replace a character - say ; - with a new line using replace-string and/or replace-regexp in Emacs.

I have tried the following commands:

  • Mx replace-string RET ; RET n

    This will replace ; with 2 characters: n .

  • Mx replace-regex RET ; RET n

    This results in the following error (shown in the minibuffer):

    Invalid use of `' in replacement text.

  • What's wrong with using replace-string for this task? Is there any other way to do it?

    Thanks.


    Mx replace-string RET ; RET Cq Cj.

  • Cq for quoted-insert ,

  • Cj is a newline.

  • Cheers!


    There are four ways I've found to put a newline into the minibuffer.

  • Co

  • Cq Cj

  • Cq 12 (12 is the octal value of newline)

  • Cx o to the main window, kill a newline with Ck, then Cx o back to the minibuffer, yank it with Cy


  • 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.

    链接地址: http://www.djcxy.com/p/38568.html

    上一篇: 多列一个缓冲区

    下一篇: 如何用Emacs中的换行符替换一个字符?