Igor
Igor

Reputation: 354

Visual Studio 2019 move text selection horizontally similar to keyboard shortcut for moving vertically [Alt + ↑] and [Alt + ↓]

in VS2019 you can move a text line up and down by using [Alt + ↑] and [Alt + ↓] keys combination. Is there a way to move a selected text horizontally inside one text line(right to left and left to right)?

PS: MOVE is not CUT&PASTE and should be done easily using only the keyboard

enter image description here

Upvotes: 0

Views: 987

Answers (2)

Sergey Vlasov
Sergey Vlasov

Reputation: 27910

You can create the following command with my Visual Commander extension to move selected text one char right (C# language):

public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
{
    EnvDTE.TextSelection ts = DTE.ActiveWindow.Selection as EnvDTE.TextSelection;
    int selectionLength = ts.Text.Length;
    DTE.ExecuteCommand("Edit.Cut");
    DTE.ExecuteCommand("Edit.CharRight");
    DTE.ExecuteCommand("Edit.Paste");
    ts.CharLeft(true, selectionLength);
}

And then assign a keyboard shortcut to it.

Upvotes: 2

Casey
Casey

Reputation: 10936

If you have mouse dragging enabled (See Tools > Options > Text Editor > General > Drag and Drop text editing), just click and drag the highlighted text to where you want it placed.

As for keyboard versions, Cut/Paste is the way to go. You can make it a little faster by using Ctrl+Left/Right to navigate the caret to each punctuation instead of each character.

Upvotes: 1

Related Questions