114

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 indent/outdent by multiples of tabSize, but that's not quite general enough for me, and I don't really want to set tabSize=1.

(In Vim I made handy shortcuts to move a line or lines up/down/left/right with ctrl-k/j/h/l - it was probably the most useful bit of Vimscript I ever wrote.)

cdyson37
  • 7,828
  • 3
  • 24
  • 16
  • 2
    Why do you want to break the consistency of indents? When someone else opens your code in a different editor it'll be all over the shop?! – Andy G Dec 20 '17 at 09:58
  • 2
    https://marketplace.visualstudio.com/items?itemName=usernamehw.indent-one-space – Alex Dec 20 '17 at 10:15
  • 2
    My use case tends to be indenting blocks of parameters to functions, which are often aligned to the open param on the preceding line. Even if I'm working with tab-like indentation, I like the symmetry of up/down/left/right rather than one thing for up/down and another for left/right. – cdyson37 Dec 20 '17 at 10:33
  • @Alex I think you have the answer, happy to accept it! – cdyson37 Dec 20 '17 at 10:38
  • 1
    VS has no built-in toolbar....strange ideed!!! – NoChance Oct 17 '18 at 09:42
  • Hi cdyson37. VS Code has added the feature. May I recommend you change the accepted answer? – Evorlor Aug 01 '19 at 15:42
  • Which answer do you think is now correct? – cdyson37 Aug 01 '19 at 18:57

8 Answers8

160

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 ‍♂️.

enter image description here

Alex
  • 59,571
  • 22
  • 137
  • 126
101

UPDATE

While these methods work, newer versions of VS Code uses the Ctrl+] shortcut to indent a block of code once, and Ctrl+[ to remove indentation.

This method detects the indentation in a file and indents accordingly.You can change the size of indentation by clicking on the Select Indentation setting in the bottom right of VS Code (looks something like "Spaces: 2"), selecting "Indent using Spaces" from the drop-down menu and then selecting by how many spaces you would like to indent.

Lloyd Armstrong
  • 1,128
  • 1
  • 6
  • 10
  • 3
    But it doesn't do 1 space if file indent is 4 spaces. OP wants 1 space in a 4-space context. – Kirill Yunussov Jul 29 '19 at 18:57
  • This is useful information, however I wanted to indent/de-indent code by exactly one space irrespective of the prevailing indentation convention of the file (for example, to make groups of arguments line up in a multi-line function call). – cdyson37 Oct 02 '19 at 10:05
  • TAB characters are into the text. You can make those TAB characters display as a single character but that strategy will blow up if the text is show in a different editor stetting with normal settings. – Craig Hicks Oct 26 '20 at 06:22
  • It will work if "Indent Using Spaces" is set in Settings, althouth that van be overriden if there are already TABS in the files. "Indent Using Spaces" was suggested below in https://stackoverflow.com/a/53463975/4376643 – Craig Hicks Oct 26 '20 at 06:35
85

No need to use any tool for that

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

Shift + Tab = Shift text right to left

Samir Kape
  • 1,733
  • 1
  • 16
  • 19
13

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:

Change Tab/Space size

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

Hope it helps.

Taher A. Ghaleb
  • 5,120
  • 5
  • 31
  • 44
5

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

garyh
  • 2,782
  • 1
  • 26
  • 28
  • I think this is for selecting columns rather than shifting them? – cdyson37 Dec 22 '17 at 09:00
  • 7
    @cdyson37 Yes, this select the columns. Then Space or Tab will shift the columns to the right. Backspace or Shift+Tab will shift the columns to the left. – garyh Jan 02 '18 at 11:29
5

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 + ]

Arjun Kesava
  • 740
  • 1
  • 10
  • 14
4

Another work-around (my installed VS Code v1.53.0)

  1. Select block of code
  2. Go to "Selection" > "Column Selection mode"
  3. Hit backspace to shift
senjoux
  • 184
  • 3
  • 13
3
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

san1512
  • 914
  • 1
  • 9
  • 16