How to replace a character with a newline in Emacs?

前端 未结 6 515
灰色年华
灰色年华 2020-12-12 09:06

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

I have tried

相关标签:
6条回答
  • 2020-12-12 09:22

    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.

    0 讨论(0)
  • 2020-12-12 09:23

    Switch to text-mode

    M-x text-mode
    

    Highlight block to indent

    Indent

    C+M \
    

    Switch back to whatever mode..

    0 讨论(0)
  • 2020-12-12 09:24

    More explicitly:

    To replace the semi colon character (;) with a newline, follow these exact steps.

    1. locate cursor at upper left of buffer containing text you want to change
    2. Type m-x replace-string and hit RETURN
    3. the mini-buffer will display something like this: Replace string (default ^ -> ):
    4. Type in the character you want to replace. In this case, ; and hit RETURN
    5. the mini-buffer will display something like this: string ; with:
    6. Now execute C-q C-j
    7. All instances of semi-colon will be replaced a newline (from the cursor location to the end of the buffer will now appear)

    Bit more to it than the original explanation says.

    0 讨论(0)
  • 2020-12-12 09:24

    inline just: C-M-S-% (if binding keys still default) than replace-string^J

    0 讨论(0)
  • 2020-12-12 09:26

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

    1. C-o

    2. C-q C-j

    3. C-q 12 (12 is the octal value of newline)

    4. C-x o to the main window, kill a newline with C-k, then C-x o back to the minibuffer, yank it with C-y

    0 讨论(0)
  • 2020-12-12 09:46

    M-x replace-string RET ; RET C-q C-j.

    • C-q for quoted-insert,

    • C-j is a newline.

    Cheers!

    0 讨论(0)
提交回复
热议问题