[英]In Intellij IDEA how do I replace text with a new line?
Say I wanted to replace all commas with commas and a new line using Intellij IDEA's replace function. 假设我想使用Intellij IDEA的替换功能用逗号和新行替换所有逗号。 What do I put in the search box? 我在搜索框中放了什么? In vim I'd use &\\r 在vim中我会使用&\\ r \\ n
You need to check the Regex box and use "\\n" for the new line character: 您需要检查正则表达式框并使用“\\ n”作为新行字符:
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
编辑:自IntelliJ 15以来缺少多线按钮,但您可以通过单击文本字段并按Alt+Enter
或Ctrl+Shift+Enter
来启用它
Hit CTRL+F
and check the regex
checkbox. 按CTRL+F
并选中regex
复选框。 Then search for ,
and replace it with ,\\n
. 然后搜索,
并将其替换,\\n
。
The easiest way that I have done it is to use the regular expression form of replace. 我做的最简单的方法是使用replace的正则表达式形式。
Chances are that you don't want to replace the {
, but just keep in my escaping them if you do want to do so. 有可能你不想替换{
,但如果你愿意的话,请继续我的逃避。
For those looking for the old multiline replace in inteliJ with version > 15.x. 对于那些寻找旧版多行替换版本> 15.x版本的人来说。 It seems somewhat hidden, but if you select multiple lines > click CTRL+F
, then immediately click CTRL+R
you are presented with the original multiline replace. 它似乎有点隐藏,但如果您选择多行>单击CTRL+F
,然后立即单击CTRL+R
您将看到原始多行替换。
This is working on Mac IntelliJ 2016.1.3
with ⌘+F > ⌘+R 这适用于Mac IntelliJ 2016.1.3
,⌘+ F>⌘+ R.
对于Mac上的Intellij Ultimate 2017.3, command-shift-enter
有效
On intellij Ultimate 2017.1: 在intellij Ultimate 2017.1:
I didn't need regex. 我不需要正则表达式。 But I could make the multiline replace appear. 但我可以让多线替换出现。
A clean approach would be to add (?m)
in front of the regular expression, which turns on the multi line mode. 一个干净的方法是在正则表达式前添加(?m)
,这将打开多行模式。 This has the advantage that you can also use it in the global file search (Ctrl-Shift-F). 这样做的好处是您还可以在全局文件搜索(Ctrl-Shift-F)中使用它。
Example: (?m)\\{(.|\\n)*?\\}
searches for multi-line blocks surrounded by curly braces. 示例:( (?m)\\{(.|\\n)*?\\}
搜索由大括号括起来的多行块。
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 所以我在Node.js中遇到了问题,我想将拒绝分成呼叫到日志并拒绝清除
reject(error)
into 成
appLogger.log(error, 'error') reject(error)
In normal mode, I did find and replace 在正常模式下,我确实找到并替换了
Find:
reject(error)
查找:reject(error)
Replace:
appLogger.log(error, 'error')\\n reject(error)
替换:appLogger.log(error, 'error')\\n reject(error)
Then in regex mode I did a second find and replace: 然后在正则表达式模式下我做了第二次查找和替换:
Find:
\\\\n
发现:\\\\n
Replace
\\n
替换\\n
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.