Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move selected code segment to the left in VS Code?

The question is, how do I move the selected block of code by one or several tabs, but not to the right (which is done by selecting a code and pressing Tab key), but to the left? Without selection each line one by one and deleting whitespace?

Moving parts of code from one place to another with differences in indent levels is a bit hard without knowing the shortcut.

What I mean (Imgur)

Thanks!

like image 211
Dmitry Polovinkin Avatar asked May 16 '18 07:05

Dmitry Polovinkin


People also ask

How do I move a selected code to the left?

SHIFT + TAB move the selected text left.

How do I move the left Tab in VSCode?

Highlight the block of code and press "Tab" key or press space 4 times. If you want to move it to the left, then hold down the Shift key and press "Tab" key.

How do I arrange my code in VS code?

Select the code you wish to sort in Visual Studio Code. Then hit the key combination Ctrl+P and type the greater than sign ( > ). Next type sort and choose Sort Lines Ascending or choose the Descending option. Now the lines you've previously selected will be sorted by the option you chose.


1 Answers

For what you want,

Shift+Tab

should do the trick. However, I would like to recommend this extension which I find easier to use when formatting blocks of text: Indent One space

Note however this extension only indents selections by exactly one space, forward or backwards.

enter image description here

like image 79
rouble Avatar answered Oct 17 '22 12:10

rouble