In Intellij IDEA how do I replace text with a new line?

前端 未结 10 1162
忘掉有多难
忘掉有多难 2020-12-24 00:00

Say I wanted to replace all commas with commas and a new line using Intellij IDEA\'s replace function. What do I put in the search box? In vim I\'d use &\\r

相关标签:
10条回答
  • 2020-12-24 00:23

    Use Multiline button, no Regex is needed.

    edit: the multiline button is missing since IntelliJ 15, but you can enable it by clicking into the textfield and pressing Alt+Enter or Ctrl+Shift+Enter

    0 讨论(0)
  • 2020-12-24 00:30

    For Intellij Ultimate 2017.3 on Mac, command-shift-enter works

    0 讨论(0)
  • 2020-12-24 00:33

    A clean approach would be to add (?m) in front of the regular expression, which turns on the multi line mode. This has the advantage that you can also use it in the global file search (Ctrl-Shift-F).

    Example: (?m)\{(.|\n)*?\} searches for multi-line blocks surrounded by curly braces.

    0 讨论(0)
  • 2020-12-24 00:41

    Hit CTRL+F and check the regex checkbox. Then search for , and replace it with ,\n.

    0 讨论(0)
  • 2020-12-24 00:42

    The is related but not exactly what you asked. But I needed it and I can imagine others do to. So I had the problem in Node.js where I wanted to split a reject into call into a log and reject for clarity

    reject(error)

    into

    appLogger.log(error, 'error') reject(error)

    In normal mode, I did find and replace

    Find: reject(error)

    Replace: appLogger.log(error, 'error')\n reject(error)

    Then in regex mode I did a second find and replace:

    Find: \\n

    Replace \n

    0 讨论(0)
  • 2020-12-24 00:44

    Ctrl + Shift + R while the replaced text is selected:

    This works for Replace in Path (WebStorm 2018.2.3):

    see here

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