string 使用 Sublime Text 在特定字符串后删除/添加换行符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13066068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 01:40:16  来源:igfitidea点击:

Remove/Add Line Breaks after Specific String using Sublime Text

stringtext-editorsublimetext2

提问by Bernd

Using Sublime Text 2 - Is it possible to insert a line break/text return after a specific String in a text file e.g. by using the Find? Replacetool?

使用 Sublime Text 2 - 是否可以在文本文件中的特定字符串之后插入换行符/文本返回,例如使用Find更换工具?

(Bonus question: Is it possible to remove all line breaks after a specific String)

(额外问题:是否可以删除特定字符串后的所有换行符)

回答by Sara

Here's how you'd do it on a Mac:

以下是您在 Mac 上的操作方法:

Command+F> type string> Control+Command+G> ESC> Right Arrow> line break

Command+ F>输入字符串> Control+ Command+ G> ESC> Right Arrow>换行符


and Windows/Linux(untested):


Windows/Linux(未经测试):

Control+F> type string> Alt+F3> ESC> Right Arrow> line break

Control+ F>输入字符串> Alt+ F3> ESC> Right Arrow>换行符


The important part being Control+Command+Gto select all matches.
Once you've selected the text you're looking for, you can use the provided multiple cursors to do whatever text manipulation you want.


最重要的部分是Control+ Command+G选择所有比赛。
一旦您选择了您要查找的文本,您就可以使用提供的多个光标来执行您想要的任何文本操作。

Protip: you can manually instantiate multiple cursors by using Command+click(or Control+click) to achieve similar results.

提示:您可以通过使用Command+单击(或Control+单击)来手动实例化多个光标以获得类似的结果。

回答by veducm

Using the Find - Replace tool, this can be accomplished in two different ways:

使用查找 - 替换工具,这可以通过两种不同的方式完成:

  1. Click in the Replace fieldand press Ctrl+ Enterto insert a newline (the field should resize but it doesn't, so it is hard to see the newline inserted).

  2. Inside the Find - Replace tool, activate the S&R regex mode(first icon on the left .*, keyboard shortcut is Alt+ Ctrl/Cmd+ Rto activate/deactivate it).

  3. Type \nin the Replace fieldwherever you want to insert a newline.

  1. 单击“替换”字段并按Ctrl+Enter插入换行符(该字段应调整大小但不会调整,因此很难看到插入的换行符)。

  2. 里面查找-替换工具,激活S&R的正则表达式模式(第一个图标左侧.*,键盘快捷键是Alt+ Ctrl/Cmd+R激活/停用)。

  3. 键入\n替换字段中,无论你要插入一个换行符。

Both solutions also work if you want to find newlines, just do it in the Find field.

如果您想查找换行符,这两种解决方案也都有效,只需在Find 字段中进行即可

回答by Otpidus

Edit->Lines->Join Line (Ctrl+J)

编辑-> 线条-> 连接线 (Ctrl+J)

回答by dbn

You should probably use multiple cursors. See the unofficial documentation, or this nice tutorial. Here's some brief instructions to set you on your way:

您可能应该使用多个游标。请参阅非官方文档或这个不错的教程。以下是一些简短的说明,可让您继续前进:

  1. Put the cursor on the string of interest.
  2. Type Command+D(Mac) or Control+D(Windows/Linux) to select the current instance of the string.
  3. Type Command+D(Mac) or Control+D(Windows/Linux) to select successive instances of the string.
  4. Alternately, type Control+Command+G(Mac) or Control+Command+Gto select allinstances of your string.
  5. Now you have multiple cursors, so insert or remove your newline as you please.
  6. (type escto exit multiple cursor mode.)
  1. 将光标放在感兴趣的字符串上。
  2. 键入Command+ D(Mac) 或Control+ D(Windows/Linux) 以选择字符串的当前实例。
  3. 键入Command+ D(Mac) 或Control+ D(Windows/Linux) 以选择字符串的连续实例。
  4. 或者,键入Control+ Command+ G(Mac) 或Control+ Command+G以选择字符串的所有实例。
  5. 现在您有多个光标,因此请随意插入或删除换行符。
  6. (键入esc以退出多光标模式。)

Have fun!

玩得开心!