Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 896
meronimo Avatar asked Jul 19 '18 09:07

meronimo


2 Answers

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

like image 100
Mark Avatar answered Nov 10 '22 00:11

Mark


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.

like image 43
jabacchetta Avatar answered Nov 10 '22 01:11

jabacchetta