Move selected text to the left or right in Visual Studio Code

40,641

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.

Animation showing how the solution works

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.

  1. Goto File->Preferences->Keyboard Shortcuts.
  2. Search Move Caret Left and Move Caret Right and add your desired keys combinations.
  3. You are done, now test it by selecting a test and firing the key combinations.
Share:
40,641

Related videos on Youtube

Mikey
Author by

Mikey

Software engineer with a passion for education

Updated on February 17, 2022

Comments

  • Mikey
    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
    Mikey about 6 years
    Thank 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
    Stefano Bossi about 6 years
    I have added a trick in my previous post, now should answer your question. Regards.
  • Ismail
    Ismail over 3 years
    I found using Ctrl + Shift + (LeftArrow || RightArrow) convenient. And for the When, use editorTextFocus && !editorReadonly
  • Chandan Kumar
    Chandan Kumar over 3 years
    Great. Helpful :)
  • aderchox
    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
    mati kepson almost 3 years
    CTRL + SHIFT + ALT if you want to create vertical line to move multiple rows at once

Related