用Sublime Text中的實際新行替換\\ n

本文翻譯自: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) (動畫用於查找真正的新行;替換它們的工作原理相同)

在此處輸入圖片說明


#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之前進行選擇,它將使用該字符作爲要替換的字符。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章