How to shift a block of code left/right by one space in VSCode?

前端 未结 7 710
再見小時候
再見小時候 2021-01-30 08:46

In VSCode, I can use alt-up and alt-down to move a line or block up or down, but I can\'t find a command to increase or decrease indent by one space.

I can inde

相关标签:
7条回答
  • 2021-01-30 08:52

    Have a look at File > Preferences > Keyboard Shortcuts (or Ctrl+K Ctrl+S)

    Search for cursorColumnSelectDown or cursorColumnSelectUp which will give you the relevent keyboard shortcut. For me it is Shift+Alt+Down/Up Arrow

    0 讨论(0)
  • 2021-01-30 08:54

    There was a feature request for that in vscode repo. But it was marked as extension-candidate and closed. So, here is the extension: Indent One space

    Unlike the answer below that tells you to use Ctrl+[ this extension indents code by ONE whtespace

    0 讨论(0)
  • 2021-01-30 08:58

    No need to use any tool for that , I solved same problem by following below 2 steps

    1. Set Tab Spaces to 1.
    2. Select whole block of code and then press Shift + Tab

    How it works Shift + Tab = Shift text right to left

    0 讨论(0)
  • 2021-01-30 09:06

    In MacOS, a simple way is to use Sublime settings and bindings.

    Navigate to VS Code.

    Click on Help -> Welcome

    On the top right, you can find Customise section and in that click on Sublime.

    Bingo. Done.

    Reload VS Code and you are free to use Command + [ and Command + ]

    0 讨论(0)
  • 2021-01-30 09:09

    Recent versions of VSCode (e.g., Version 1.29 at the time of posting this answer) allow you to change the Tab/Space size to 1 (or any number between 1 and 8). You may change the Tab/Space size from the bottom-right corner as shown in the below image:

    Click on Spaces:4. Then, select Indent Using Spaces or Indent Using Tabs and choose the size 1.

    Hope it helps.

    0 讨论(0)
  • 2021-01-30 09:09
    Current Version 1.38.1
    

    I had a problem with intending. The default Command+] is set to 4 and I wanted it to be 2. Installed "Indent 4-to-2" but it changed the entire file and not the selected text.

    I changed the tab spacing in settings and it was simple.

    Go to Settings -> Text Editor -> Tab Size

    0 讨论(0)
提交回复
热议问题