【问题标题】:Visual Studio Code - Indent single line with tabulator-keyVisual Studio Code - 使用制表键缩进单行
【发布时间】:2018-07-19 09:45:23
【问题描述】:

我想知道是否可以在不删除标记文本的情况下使用 tab 键缩进一行。

在 GIF 的第一部分中您可以看到 Visual Studio Code,在第二部分中您可以看到 Atom。 Atom 显示所需的行为。

到目前为止,在 VS Code 中以这种方式缩进多行是可能的,它也适用于 backtab,但不适用于 tab 和单行。

这是错误还是正常行为??

我的设置:
Visual Studio Code:版本 1.25.1 (MacOS 10.13.6 High Sierra)
Visual Studio 代码:版本 1.25.1 (Ubuntu 18.04 LTS)

【问题讨论】:

    标签: visual-studio-code indentation text-indent


    【解决方案1】:
    You could use this default keybinding:
    
    {
      "key": "ctrl+]",
      "command": "editor.action.indentLines",
      "when": "editorTextFocus && !editorReadonly"
    }
    

    制表单行或多行。如果您希望将其绑定到 tab,您可以将其修改为:

    {
      "key": "tab",
      "command": "editor.action.indentLines",
      "when": "editorHasSelection && editorTextFocus && !editorReadonly"
    }
    

    我添加了editorHasSelection 子句,因此它在您的线路上选择某些内容时运行,但随后您将失去正常的简单 tab 行为(您不'不喜欢)。

    【讨论】:

    • 谢谢你,你的第二个推荐正是我想要的
    【解决方案2】:

    据我了解,这是预期的行为。要缩进一行,您需要:

    • 将光标放在行首,然后制表符
    • 选择整行(Mac:Command+i,Windows/Linux:Ctrl+i)然后tab
    • 使用 indent line 命令,可以使用 GIF 中显示的所选单词来完成(Mac:Command+],Windows/Linux:Ctrl+]

    不过,an extension 可能会提供您想要的行为。

    【讨论】:

      【解决方案3】:

      在这里添加另一种风味:

      如果您希望 tab 像 shift-tab 一样工作(您不必突出显示任何内容),并且如果您使用 tab 作为接受自动完成建议的键,请使用此设置:

      {
        "key": "tab",
        "command": "editor.action.indentLines",
        "when": "!suggestWidgetVisible && editorTextFocus && !editorReadonly"
      }
      

      【讨论】:

        猜你喜欢
        • 2017-12-28
        • 2016-07-15
        • 2016-09-05
        • 2019-10-31
        • 1970-01-01
        • 1970-01-01
        • 2015-03-28
        • 2017-06-07
        • 2017-07-09
        相关资源
        最近更新 更多