欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

用Sublime Text中的实际新行替换\\ n

程序员文章站 2024-01-08 10:58:52
...

本文翻译自:Replace \n with actual new line in Sublime Text

How can I replace \\n in Sublime Text with real in-editor displayed new line so: 如何用实际的编辑器显示的新行替换Sublime Text中的\\n ,因此:

foo\nbar

becomes: 变成:

foo
bar

in the editor when I view the file in it. 在编辑器中查看文件时。


#1楼

参考:https://stackoom.com/question/1O53u/用Sublime-Text中的实际新行替换-n


#2楼

使用Find > Replace或( Ctrl + H )打开“ Find What / Replace With窗口,然后使用Ctrl + Enter在“ Replace With 输入框中指示新行。


#3楼

Turn on Regex Search and Replace (icon most to the left in search and replace bar or shortcut Alt + R ) 打开正则表达式搜索和替换(搜索和替换栏或快捷键Alt + R中最左侧的图标)

Find What: \\\\n 查找内容: \\\\n
Replace with: \\n 替换为: \\n

Cheers 干杯


#4楼

In Sublime Text (with shortcuts on Mac): 在Sublime Text中(在Mac上为快捷方式):

  1. Highlight the text that you want to search to apply Find & Replace 突出显示要搜索以应用“查找和替换”的文本

  2. Go to Menu > Find > Replace... (Keyboard Shortcut: Alt + Command + F) 转到菜单>查找>替换...(键盘快捷键:Alt + Command + F)

  3. In the Find & Replace tool, enable Regular Expression by clicking on the button which looks like [.*] (Keyboard Shortcut: Alt + Command + R) 在“查找和替换”工具中,通过单击看起来像[。*]的按钮来启用正则表达式(键盘快捷键:Alt + Command + R)

  4. In Find What, type: \\\\n 在“查找内容”中,键入: \\\\n

    Note: The additional \\ escapes the Regular Expression syntax when searched. 注意:搜索时,附加\\转义正则表达式语法。

  5. In Replace With, type: \\n 在“替换为”中,键入: \\n

  6. Click on the 'Replace All' button (Keyboard Shortcut: CTRL + Alt + Enter) 单击“全部替换”按钮(键盘快捷键:CTRL + Alt + Enter)

Your literal text \\n will then turn into an actual line break. 您的文字文本\\n将变成实际的换行符。


#5楼

Fool proof method (no RegEx and Ctrl + Enter didn't work for me as it was just jumping to next Find ): 简便的方法 (没有RegEx和Ctrl + Enter对我不起作用,因为它只是跳转到下一个Find ):

First, select an occurrence of \\n and hit Ctrl + H (brings up the Replace... dialogue, also accessible through Find -> Replace... menu). 首先,选择一个\\n并按Ctrl + H (弹出“ Replace...对话框,也可以通过“ Find -> Replace...菜单进行访问)。 This populates the Find what field. 这将填充“ Find what字段。

Go to the end of any line of your file (press End if your keyboard has it) and select the end of line by holding down Shift and pressing (right arrow) EXACTLY once. 转到文件任何行的末尾(如果有键盘,请按End结束 )),然后按住Shift完全按一次 (向右箭头)以选择行尾。 Then copy-paste this into the Replace with field. 然后将其复制粘贴到“ Replace with字段中。

(the animation is for finding true new lines; works the same for replacing them) (动画用于查找真正的新行;替换它们的工作原理相同)

用Sublime Text中的实际新行替换\\ n


#6楼

None of the above worked for me in Sublime Text 2 on Windows. 在Windows上的Sublime Text 2中,上述方法都不适合我。

I did this: 我这样做:

  • click on an empty line; 单击一个空行;
  • drag to the following empty line (selecting the invisible character after the line); 拖动到以下空行(选择该行后的不可见字符);
  • press ctrl+H for replace; 按ctrl + H进行替换;
  • input desired replacement character/string or leave it empty; 输入所需的替换字符/字符串或将其留空;
  • click "Replace all"; 点击“全部替换”;

By selecting before hitting ctrl+H it uses that as the character to be replaced. 通过在按下ctrl + H之前进行选择,它将使用该字符作为要替换的字符。