Visual Studio Code - Indent single line with tabulator-key
Asked Answered
G

3

6

I would like to know if its possible to indent a single line with the tab-key without deleting the marked text.

In the first part of the GIF you see Visual Studio Code and in the second part Atom. Atom shows the desired behaviour.

First: VS Code, Second: ATOM-Editor

Thus far it is possible to indent multiple lines this way in VS Code, it also works with backtab, but not with tab and a single line.

VS Code indent multiple lines

Is this a bug or normal behavior??

My Setup:
Visual Studio Code: Version 1.25.1 (MacOS 10.13.6 High Sierra)
Visual Studio Code: Version 1.25.1 (Ubuntu 18.04 LTS)

Gourami answered 19/7, 2018 at 9:45 Comment(0)
S
2
You could use this default keybinding:

{
  "key": "ctrl+]",
  "command": "editor.action.indentLines",
  "when": "editorTextFocus && !editorReadonly"
}

to tab single or multilines. If you want that bound to tab you could modify it to:

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

I added the editorHasSelection clause so it operates only when something is selected on your line, but then you would lose the normal simple tab behavior (that you don't like).

Saddler answered 19/7, 2018 at 14:2 Comment(1)
thanks man, your second recommendation does exactly what i wantGourami
C
1

From my understanding, this is the expected behavior. To indent a single line, you'd need to either:

  • place cursor at beginning of the line and then tab
  • select the entire line (Mac: Command+i, Windows/Linux: Ctrl+i) and then tab
  • use the indent line command, which can be done with the words selected as shown in your GIF (Mac: Command+], Windows/Linux: Ctrl+])

There may be an extension available that gives you your desired behavior, though.

Collimore answered 19/7, 2018 at 13:56 Comment(0)
H
0

Just adding another flavor here:

In case you want tab to work like shift-tab (where you don't have to highlight anything), AND if you're using tab as the key to accept autocomplete suggestions, use this setting:

{
  "key": "tab",
  "command": "editor.action.indentLines",
  "when": "!suggestWidgetVisible && editorTextFocus && !editorReadonly"
}
Hepcat answered 20/9, 2021 at 17:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.