meronimo
meronimo

Reputation: 75

Visual Studio Code - Indent single line with tabulator-key

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)

Upvotes: 7

Views: 2456

Answers (3)

Alex E
Alex E

Reputation: 307

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"
}

Upvotes: 0

jabacchetta
jabacchetta

Reputation: 50008

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.

Upvotes: 1

Mark
Mark

Reputation: 180631

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).

Upvotes: 2

Related Questions