Move selected text to the left or right in Visual Studio Code
Solution 1
This feature has been implemented by a pull request some time ago.
To use it you need to bind the editor.action.moveCarretLeftAction
and editor.action.moveCarretRightAction
actions in the keyboard shortcuts editor.
Solution 2
Moving blocks of text
A workaround for moving a block of text of just one space is to use the "column selection" feature of Visual Studio. here the detailed instruction:
- move the cursor at the upper left corner of the block of text you want to shift;
- click with the mouse holding down shift + alt, on the down left corner of the block of text you want to shift;
- now you could insert as many spaces as you want.
If you need more info on Block Selection in Visual Studio you could easily find information on the official documentation or here: enter link description here Pay attention in the link the shortcut is wrong, at least for me.
Indentation
For moving the text right and left you can use TAB key:
- TAB move the selected text right
- SHIFT + TAB move the selected text left
Solution 3
Ok, so these answers didn't really help me as I am a beginner, here is what I did.
- Goto
File->Preferences->Keyboard Shortcuts
. - Search
Move Caret Left
andMove Caret Right
and add your desired keys combinations. - You are done, now test it by selecting a test and firing the key combinations.
Related videos on Youtube
Comments
-
Mikey over 2 years
In Visual Studio Code, is there any command currently to move the selected text to the left or right?
I'm not talking about indentation btw.
-
Mikey about 6 yearsThank you for the input but I was not talking about indentation but actually shifting the words one character/word to the left/right.
-
Stefano Bossi about 6 yearsI have added a trick in my previous post, now should answer your question. Regards.
-
Ismail over 3 yearsI found using
Ctrl
+Shift
+ (LeftArrow
||RightArrow
) convenient. And for the When, useeditorTextFocus && !editorReadonly
-
Chandan Kumar over 3 yearsGreat. Helpful :)
-
aderchox almost 3 years@Ismail not a good one in my opinion b/c that key combination already does text selection in chunks.
-
mati kepson almost 3 yearsCTRL + SHIFT + ALT if you want to create vertical line to move multiple rows at once