在Visual Studio Code中查找并​​替换为换行符

本文翻译自:Find and replace with a newline in Visual Studio Code

I am trying out the new Microsoft Visual Studio Code editor in Linux Fedora environment. 我正在Linux Fedora环境中试用新的Microsoft Visual Studio Code编辑器。 I would like to know how to replace new line (\\n) in place of some other text. 我想知道如何用换行(\\ n)代替其他文本。

For example, I have html text like this 例如,我有这样的html文本

<tag><tag> 

which I would like to replace as 我想替换为

<tag>
<tag>

In sublime I would use regex pattern and find "><" and replace with ">\\n<" How do I accomplish this in Visual Studio Code? 在崇高的环境中,我将使用正则表达式模式并找到“> <”并替换为“> \\ n <”如何在Visual Studio Code中完成此操作?


#1楼

参考:https://stackoom.com/question/23Lon/在Visual-Studio-Code中查找并-替换为换行符


#2楼

在此处输入图片说明

Remember to check the rightmost regex icon. 记住要检查最右边的正则表达式图标。

If you use the global search ( ctrl + shift + f ) you can simply insert newlines by pressing shift + enter . 如果使用全局搜索( ctrl + shift + f ),则只需按shift + enter即可插入换行符。

在此处输入图片说明


Version 1.30: As of November 2018 and VSCode 1.30 , multiline support in the global search box is supported. 版本1.30:自2018年11月和VSCode 1.30起 ,支持全局搜索框中的多行支持。


Version 0.10.6: According to the release notes, this was finally added in version 0.10.6 0.10.6版:根据发行说明, 此内容最终已添加到0.10.6版中


Old answer: It seems like this is not possible in the current version (0.3.0) of VScode. 旧答案:在当前版本的VScode(0.3.0)中似乎无法实现。 The replace function (ctrl+h) seems to interpret \\n as text, and not a new line. 替换功能(ctrl + h)似乎将\\ n解释为文本,而不是换行。

I'm sure this will get fixed in an upcomming release. 我相信这将在即将发布的版本中解决。


#3楼

A possible workaround would be to use the multi-cursor. 可能的解决方法是使用多光标。 select the >< part of your example use Ctrl+Shift+L or select all occurrences. 选择示例的> <部分,请使用Ctrl + Shift + L或选择所有出现的示例。 Then use the arrow keys to move all the cursors between the tags and press enter to insert a newline everywhere. 然后使用箭头键在标签之间移动所有光标,然后按Enter键在所有位置插入换行符。

This won't work in all situations. 这并非在所有情况下都有效。

You can also use Ctrl+D for select next match, which adds the next match to the selection and adds a cursor. 您也可以使用Ctrl + D选择下一个匹配项,这会将下一个匹配项添加到选择项中并添加光标。 And use Ctrl+K Ctrl+D to skip a selection. 并使用Ctrl + K Ctrl + D跳过选择。


#4楼

In version 1.1.1: 在1.1.1版中:

  • Ctrl+H Ctrl + H
  • Check the regular exp icon .* 检查常规exp图标.*
  • Search: >< 搜索: ><
  • Replace: >\\n< 替换: >\\n<

#5楼

With VS Code release 1.38 you can type Control + Enter in the editor find box to add a newline character. 使用VS Code 版本1.38,您可以在编辑器的“查找”框中键入Control + Enter ,以添加换行符。

在此处输入图片说明

With VS Code release 1.30 you can type Shift + Enter in the search box to add a newline character without needing to use regex mode. 使用VS Code 版本1.30,您可以在搜索框中键入Shift + Enter ,以添加换行符,而无需使用正则表达式模式。

在此处输入图片说明

Since VS Code release 1.3 , the regex find has supported newline characters. 从VS Code 版本1.3开始 ,正则表达式查找支持换行符。 To use this feature set the find window to regex mode and use \\n as the newline character. 要使用此功能,请将查找窗口设置为正则表达式模式,并使用\\n作为换行符。

VS Code中的多行查找gif


#6楼

还要注意,在点击了正则表达式图标之后,要用换行符实际替换\\n文本,我必须使用\\\\n作为搜索并使用\\n作为替换。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值