简体   繁体   English

如何在 Visual Studio Code 中递归地取消缩进代码?

[英]How can I recursively unindent code in Visual Studio Code?

I have a block of code that has one too many indentations on every nested block in Visual Studio Code, two tabs(four spaces) per nested block.我有一段代码,在 Visual Studio Code 中的每个嵌套块上都有一个太多的缩进,每个嵌套块有两个制表符(四个空格)。 I want one tab(two spaces) per nested block.我想要每个嵌套块一个选项卡(两个空格)。 I can unindent a block with shift + tab , but if I unindent further, the nesting structure will not be preserved.我可以使用shift + tab取消缩进一个块,但是如果我进一步取消缩进,嵌套结构将不会被保留。

Is there a command in VS Code to recursively unindent an entire file or selection without having to manually remove each unwanted indentation(ie one tab from the first block, two tabs from the second block, etc.)? VS Code 中是否有一个命令可以递归地取消缩进整个文件或选择,而无需手动删除每个不需要的缩进(即第一个块中的一个选项卡,第二个块中的两个选项卡等)? I wish to only change the indentation, so I cannot use automatic formatting which will make other changes like Prettier.我希望只更改缩进,所以我不能使用自动格式化,这会像 Prettier 这样进行其他更改。

    <div class="grid-container">
        <div class="grid-item">
            <a href="https://www.goodreads.com/book/show/17255186-the-phoenix-project" target="_blank">
            <img src="https://i.gr-assets.com/images/S/compressed.photo.goodreads.com/books/1361113128l/17255186.jpg">
            </a>
        </div>
    </div>
  • Select 2 tabs (4 spaces) at the start of a line Select 2 个制表符(4 个空格)在行首
  • Shift + Ctrl + L Shift + Ctrl + L
  • type 1 tab (or 2 spaces)键入 1 个制表符(或 2 个空格)
  • Esc (leave multi cursor mode) Esc (离开多cursor模式)

If only part of the file needs unindent如果只有部分文件需要取消缩进

  • Select 2 tabs (4 spaces) at the start of a line Select 2 个制表符(4 个空格)在行首
  • use Ctrl + D as many times as you want/need, till all indents on all lines needed are selected根据需要/需要多次使用Ctrl + D ,直到选择所有需要的行上的所有缩进
  • type 1 tab (or 2 spaces)键入 1 个制表符(或 2 个空格)
  • Esc (leave multi cursor mode) Esc (离开多cursor模式)

Multi Cursor method works for up to 10000 indents.多 Cursor 方法最多可用于 10000 个缩进。 If needed repeat for the next section in the file.如果需要,请重复文件中的下一部分。

Or with Find/Replace或使用查找/替换

  • Select 2 tabs (4 spaces) at the start of a line Select 2 个制表符(4 个空格)在行首
  • Ctrl + H (start replace) Ctrl + H (开始替换)
  • in replace box type: 1 tab (or 2 spaces)在替换框中类型:1 个制表符(或 2 个空格)
  • if only part of the file needs unindent如果只有文件的一部分需要取消缩进
    • select part of the file select 部分文件
    • tick inside selection in the Find dialog在“查找”对话框中勾选内部选择
  • click Replace All in the Find dialog在查找对话框中单击Replace All

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何设置 Visual Studio Code 的 Emmet 优先级? - How can I set the Emmet priority of Visual Studio Code? 如何在 Visual Studio Code 中启用 PHP 语法突出显示? - How can I enable PHP Syntax highlighting in Visual Studio Code? 如何在 Visual Studio Code 中运行这个 JavaScript 蛇游戏? - How can I run this JavaScript snake game in Visual Studio Code? 如何与其他人共享用 visual studio 代码编写的 html 代码的 output? - How can I share the output of an html code written in visual studio code with someone else? 如何将Visual Studio代码上的本地网站推送到在Azure上部署的Webapp - How can I push my local website on visual studio code to a webapp I deployed on Azure 如何在 Visual Studio Code 中同时自动完成 HTML 和 Django-HTML? - How can I autocomplete both HTML and Django-HTML simultaneously in Visual Studio Code? 如何禁用 Visual Studio Code 自动修剪 HTML 类的空白? - How can I disable Visual Studio Code auto trimming whitespace of my HTML classes? 使用 Visual Studio Code,如何更改索引页面的高度和宽度大小? - Using Visual Studio Code, how can I change the Index page height and width size? 如何在 Visual Studio Code 中禁用自动换行符? - How can I disable auto new-line in Visual Studio Code? 如何在 Visual Studio Code 中查看实时服务器上的两个 html 页面? - How Can I View Two html pages on live server in Visual Studio Code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM