你不知道的VS Code冷门快捷技巧(译文)
【关于TalkX】
TalkX是一款基于GPT实现的IDE智能开发插件,专注于编程领域,是开发者在日常编码中提高编码效率及质量的辅助工具,TalkX常用的功能包括但不限于:解释代码、中英翻译、性能检查、安全检查、样式检查、优化并改进、提高可读性、清理代码、生成测试用例等。
TalkX建立了全球加速网络,不需要考虑网络环境,响应速度快,界面效果和交互体验更流畅。并为用户提供了的密钥,不需要,不需要自备账号,不需要魔法。
TalkX产品支持: (包括 IDEA、、、 )、、VS Code、.
73%.
Did you know that 73% of on the same code ?
你知道全球 73% 的开发人员依赖同一个代码编辑器吗?
Yes, the 2023 Stack are in, and yet again, Code was by far the most used .
没错,2023 年 Stack 开发人员调查结果已经出炉, Code 再次成为迄今为止使用最多的开发环境。
And we all know why: it’s .
我们都知道原因:它太棒了。
But are we fully its ? In this , we some VS Code that with local , , and rapid line , . Let us start using them to our goals than ever.
但我们是否充分挖掘了它的潜力?在本文中,我们将介绍一些引人注目的 VS Code 功能,这些功能包括本地源代码控制、动画键入和快速删除行等,可提高工作效率。让我们开始使用它们,以前所未有的速度实现编码目标。
1. view: local 1. 时间轴视图:本地源控制
The view gives us built-in .
时间轴视图为我们提供了内置的源控制功能。
Many of us know how Git and other tools are, us track file and back to a point when .
我们中的许多人都知道 Git 和其他源控制工具有多么有用,它们可以帮助我们轻松跟踪文件更改,并在需要时返回到上一点。
So the view in VS Code an of to a file, such as Git , file saves, and test runs.
因此,VS Code 中的时间轴视图提供了与文件相关的重要事件的自动更新时间轴,如 Git 提交、文件保存和测试运行。
this view to see a list of of to the file. Here it’s file saves, but also Git where the file was .
展开该视图可看到与当前文件相关的事件快照列表。这里不仅包括文件的保存,还包括文件的 Git 提交。
Hover over the item to view the date and time when VS Code made the .
将鼠标悬停在快照项目上,可查看 VS Code 制作快照的日期和时间。
a item to see a diff view the the file at the time and the file .
选择快照项目,可查看差异视图,显示文件在快照时间和当前文件之间的变化。
2. : no more Ctrl + S 2. 自动保存:不再按 Ctrl + S
Can you count how many times you’ve used this ? You do it now.
你能数出使用过多少次这个快捷键吗?你现在可能会不自觉地使用它。
The saves files as we work on them, the need for . With , we Ctrl + S , save time, and gain of with the to the files.
自动保存功能会在我们工作时自动保存文件,无需手动保存。有了自动保存功能,我们可以消除按 Ctrl + S 的疲劳,节省时间,并确保始终使用最新的文件更改。
It’s not , and it’s up to you to weigh the pros and cons — which we cover here.
但自动保存功能并不完美,您需要权衡利弊,我们将在这里全面介绍。
Stop your code
By Tari Ibaba / Last on March 30, 2023
Use File > Auto Save to the .
使用“文件”>“自动保存”可以轻松启用该功能。
3. Do with 3. 使用命令面板执行任何操作
you do in VS Code apart from is a “”.
在 VS Code 中,除了键入之外,几乎所有操作都是 “命令”。
let us tasks the , and they file- , , , and , each to of your .
命令让我们在编辑器中完成任务,它们包括文件相关命令、导航命令、编辑命令和终端命令,每个命令都经过优化设计,以增强编辑体验的不同方面。
So with we for a and to the .
因此,使用命令调板,我们只需搜索命令并选择即可执行相关操作。
To open the , use this :
要打开 “命令调板”,请使用以下快捷键:
/Linux: Ctrl + Shift + P
Mac: Shift + + P
As you , those to the right are a way to run the with the .
正如你所猜测的那样,右侧的键盘快捷键是使用键盘运行命令的更快方法。
The key of the over is when there’s a a , or you’re for a you’re not sure .
与快捷键相比,命令调板的主要优势在于当某个命令没有快捷键,或者你正在寻找一个你不确定是否存在的命令时。
4. Go to file 4. 快速进入文件
The mouse is too slow.
鼠标太慢了。
Yes, you can click on the file in the pane, but for a much use Ctrl + P to for and open a file in your .
是的,你可以点击资源管理器窗格中的文件,但要想更快,可使用 Ctrl + P 搜索并打开项目中的特定文件。
Hold Ctrl and press Tab to cycle the list of files open in an .
按住 Ctrl 键并按 Tab 键,可循环查看编辑器实例中当前打开的文件列表。
You can even use Alt + Left and Alt + Right to these open files.
你甚至可以使用 Alt + Left 和 Alt + Right 在这些打开的文件之间快速导航。
All these are much ways to get to a file than using the .
所有这些方法都比使用光标更快地找到文件。
5. Go to line 5. 快速跳转指定行
Jump, don’t .
跳转,不要滚动。
to a line is when you need to at line . By to those lines, you can the code in that , , and the issue.
在调试过程中,当你需要在特定行号处遇到错误时,快速导航到某一行是非常有价值的。通过跳转到这些行,你可以在特定上下文中检查代码、评估变量并排除故障。
Use the Ctrl + G for this.
为此,请使用 Ctrl + G 快捷键。
6. line 6. 快速删除行
You’ve got to the line now, what if you want to it?
你现在已经到了这一行,如果要删除它怎么办?
Will you drag and drag to and then press ? Will you press until every is gone?
你会拖啊拖突出显示然后按 键吗?你会不知疲倦地按 直到删除所有字符吗?
Or, will you use the Ctrl + Shift + K to that and more lines in a of ?
或者,你会使用 Ctrl + Shift + K 快捷键,在几秒钟内快速删除这一行和其他几十行吗?
7. Enjoy with 7. 使用流畅的光标享受打字乐趣
VS Code has this that the as it moves, like in MS Word. This makes feel more fluid and , as well as us a and more feel as we the lines of code and place the at .
VS Code 具有平滑光标功能,可以像 MS Word 一样在光标移动时显示动画。这让输入感觉更流畅、更精练,也让我们在浏览代码行并将光标置于不同点时感觉更流畅、更自然。
To turn it on, open UI in the and for “smoot caret”.
要打开它,请打开 "命令面板 "中的 “设置 UI”,然后搜索 “smoot caret”。
We are for the : Caret , which has 3 :
我们要找的是编辑器: 光标平滑焦距动画设置,该设置有 3 个选项:
1、off: No
1、关闭: 无平滑光标动画
2、: Only the when we place it in the code.
2、(明确 只有当我们在代码中明确放置光标时,光标才会产生动画。
3、on: is - when .
3、on: 始终启用平滑光标动画 - 包括键入时。
Set it to on to get the full .
将其设置为开启,即可获得完整的视觉体验。
8. code 8. 快速格式化代码
is all about code by it in a and .
格式化就是以结构化和一致的方式组织代码,从而提高代码的可读性。
And if you’ve been doing this , you need to know that there’s a way.
如果你一直在手动操作,那么你需要知道有更好的方法。
Yes, you need to start code with the , in the . on the file’s , a “” will be used to the code using rules of , line , and , etc.
是的,你需要使用 "命令面板 "中的 "格式化文档 "命令开始自动格式化代码。根据当前文件的语言,将使用特定的 "默认 "格式器,使用各种缩进、行长、大括号和小括号等规则来格式化代码。
While there’s a built-in JS/TS , for a more , I the .
虽然有一个相当不错的内置 JS/TS 格式化器,但要想获得更强大的解决方案,我强烈推荐使用 扩展。
After , you’ll set it as your .
安装后,您将把它设置为默认格式化程序。
When you use over , there’s a you to make a bit :
**
在使用手动保存而非自动保存时,有一项功能需要启用,以使格式化更容易一些:**
-: On Save: “ a file on save. A must be , the file must not be saved after delay, and the must be down”. It is by .
编辑器:保存时格式化:“保存时格式化文件。格式化程序必须可用,延迟后不得保存文件,并且编辑器必须关闭”。默认情况下它是禁用的。
So with this on, VS Code will your code with the when you save the file with Ctrl + S, as you saw in the above demo.
因此,启用此设置后,当您使用 Ctrl + S 保存文件时,VS Code 将自动使用当前默认格式化程序格式化您的代码,如上面的演示中所示。
When you do , On Save doesn’t work, and it can get to open the when you’re every now and then. And that’s what are for:
自动保存时,"保存时格式化 "不起作用,而且当你不时格式化时,连续打开 "命令调板 "会很乏味。这就是键盘快捷键的作用:
: Shift + Alt + F
Mac: Shift + + F
Linux: Ctrl + Shift + I
I’m on and , I don’t like this ; makes me every now and then, and Shift + Alt + F got after a while.
我使用的是 系统,我个人并不喜欢这个默认快捷键;自动保存让我时不时就要格式化一次,而且 Shift + Alt + F 用久了也会让人心烦意乱。
So I it to Ctrl + D, Ctrl + D - a chord that’s much to press and , and has no . I you do the same.
所以我把它改成了 Ctrl + D, Ctrl + D - 一个更容易按、更容易记,而且没有冲突键绑定的键盘快捷键。我建议你也这样做。
9. Save time with multi- 9. 使用多光标编辑节省时间
One of the wow in my VS Code days, the multi- lets you place at , and or the same text times. This up time and , as we get tasks done with rapid code .
多光标编辑是我最早使用 VS Code 时的一大亮点,它可以让你在不同的点上放置多个光标,并多次删除或插入相同的文本。这加快了编辑时间,大大提高了工作效率,因为我们可以在快速创建代码的同时高效地完成重复性工作。
Of , when , there’s at least one . Use Alt + Click to add more.
当然,在编辑时,总是至少有一个光标。使用 Alt + 单击可添加更多光标。
You can also add a above or below the line, with Ctrl + Alt + Down or Ctrl + Alt + Up.
您还可以使用 Ctrl + Alt + Down 或 Ctrl + Alt + Up 在当前行的正上方或下方轻松添加光标。
These run the Add Add .
这些快捷键分别运行 Add Above 和 Add Below 命令。
10. new / file 10. 快速创建新文件夹/文件
There’s no where we don’t new and files, and if there was a way to file/ , all the time saved would add up to give us a boost.
如果有一种方法可以加快文件/文件夹的创建速度,那么节省下来的所有时间都将大大提高我们的工作效率。
If you’ve been new files and in VS Code with the new file and new , then yes, there is a way.
如果你一直在 VS 代码中使用新建文件和新建文件夹按钮创建新文件和文件夹,那么是有办法的。
of your mouse to those small , did you know you can just -click on the panel to a new file?
你知道吗,与其不停地移动鼠标寻找这些小按钮,你只需双击资源管理器面板就能创建新文件。
How about a new ? Well, are files, and when you’re a new file, you can use the / to a and new and sub- to that file.
新建一个文件夹怎么样?好吧,没有文件,文件夹就什么都不是,当您创建新文件时,您可以轻松地使用 / 字符来指示层次结构并创建新文件夹和子文件夹来包含该文件。
It would be even more to use , which is what I did.
使用键盘快捷键会更有效率,我就是这么做的。
As a Atom fan, I had used to the A and Shift + A for new files and ; I knew what I had to do.
作为 Atom 的老粉丝,我很快就习惯了分别用于创建新文件和文件夹的 A 和 Shift + A 快捷键;我知道自己该做什么。
Since A and Shift + A are keys we code with, I the when here to make sure they only a new file/ when the pane has focus and there’s no in the .
由于 A 和 Shift + A 显然是我们编码时使用的按键,因此我在这里加入了 when 值,以确保它们只在资源管理器窗格有焦点且当前编辑器中没有活动光标时创建新文件/文件夹。
So to use these when , you’ll have to focus on the pane first; click on it, or use Ctrl/ + Shift + E.
因此,要在键入时使用这些快捷键,你必须先关注资源管理器窗格;点击它,或使用 Ctrl/ + Shift + E。
Key 要点
local with view; in
pane by .
使用时间轴视图启用本地源代码控制;默认情况下可在资源管理器窗格中使用。
files with File > .
使用文件 > 自动保存功能自动保存文件。
Run in with Ctrl + Shift + P or Shift +
+ P.
使用 Ctrl + Shift + P 或 Shift + + P 在命令面板中运行命令。
Go to a file with Ctrl + P, open files with Alt +
Left/Right or Ctrl + Tab.
用 Ctrl + P 转到文件,用 Alt + 左/右或 Ctrl + Tab 在打开的文件间导航。
Go to a line with Ctrl + G.
用 Ctrl + G 转到某一行。
a line with Ctrl + Shift + K .
用 Ctrl + Shift + K 删除一行。
with : Caret
.
使用编辑器启用平滑键入: 光标平滑键入动画设置。
code with , use ,
to Ctrl + D, Ctrl + D .
使用格式化文档命令格式化代码,使用 ,将快捷键改为 Ctrl + D、Ctrl + D 。
Use at once with Alt + Click. Ctrl + Alt + Up/Down
adds a above/below.
使用 Alt + Click 同时使用多个光标。Ctrl + Alt + 上/下可在上方/下方添加光标。
Move a line up or down with Alt/ + Up/Down in /Mac.
在 /Mac 中使用 Alt/ + 上/下移动一行。
a new file by - the pane or set a . a new file in a new with
“/file.ext”.
双击资源管理器窗格或设置自定义键盘快捷键创建新文件。用 "/file.ext "在新文件夹中创建新文件。
Check out the VS Code Key docs to learn more about and how to them. It a list of all the VS Code in your .
查看 VS Code Key 文档,了解更多有关键盘快捷键以及如何自定义它们的信息。其中包括操作系统中所有默认 VS 代码快捷键的完整列表。
Final 最后的想法
Code is more than just a text — it’s a tool that, when , can boost your and your . The ten tips and we’ve are just the tip of the . As you to VS Code, you will a of other and that will your .
Code 不仅仅是一个文本编辑器–它还是一个强大的工具,只要熟练掌握,就能大大提高你的工作效率,简化你的编码工作流程。我们探讨的十个技巧和窍门只是冰山一角。在继续浏览 VS Code 的过程中,你还会发现大量其他功能和快捷方式,它们将进一步提升你的编码体验。
So, keep , keep , and : the key to lies not just in the code , but also in the tools you use to write it.
因此,请不断探索,不断学习,并记住:高效编码的关键不仅在于代码本身,还在于你用来编写代码的工具。
【参考文献】
上述译文仅供参考,具体内容请查看⬇️链接,解释权归原作者所有
文章:[10 VS Code tips & for ]