如何在 Visual Studio Code 中编辑所有行 [英] How to edit all lines in Visual Studio Code

查看:34
本文介绍了如何在 Visual Studio Code 中编辑所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据列表,我需要在行首和行尾放置一个 ' 符号.所以原始数据是这样的:

I have a list of data to which I need to put a ' symbol at the start of the line and at the end of the line. So the original data looks like this:

abcde
cdeab
deabc
eabcd

而且我希望所有的行看起来像这样:

And I want all of the lines to look like this:

'abcde'
'cdeab'
'deabc'
'eabcd'

在我的真实数据中,我会有 10,000 行.因此,如果我可以执行诸如 Ctrl+Shift+A 之类的操作来选择整个文档,然后使用一些神奇的快捷方式来更改选择所有行编辑所有完美的线条!

In my real data, I would have 10,000 of lines. So if I can do something like Ctrl+Shift+A to select the entire document and then have some magic shortcut to change from selecting all lines to editing all lines that would be perfect!

推荐答案

您可以编辑并替换为正则表达式:

You could edit and replace with a regex:

查找(Ctrl+F):

^(.+)$

替换:

'$1'

此正则表达式查找一行中的任何内容并将其括在引号内.$1 指的是正则表达式中括号内匹配的任何内容.在这种情况下,它是一个或多个字符".即上线的一切.请务必勾选正则表达式图标.

This regex finds any content on a line and wraps it inside quotes. The $1 refers to whatever is matched inside the parentheses in the regex. In this case, it's "one or more characters" i.e. everything on the line. Be sure to tick the regex icon.

如果每一行在内容之前可能有也可能没有空格,并且你希望每一行都有一个空格,试试这个:

If every line may or may not have a space before the content, and you want every line to have a space, try this:

查找:

^ ?(.+)$

替换(注意第一个引号前的空格):

Replace (notice the space before the first quote):

 '$1'

这篇关于如何在 Visual Studio Code 中编辑所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆