Notinlist
Notinlist

Reputation: 16640

Visual Studio: Cursor position after pasting

I would like to keep the cursor position after pasting, so finally the cursor would be at the beginning of the pasted text. This would speed up some text editing scenarios for me. I searched in Tools / Options, but I did not manage to find any settings for it. Searched the net too with no luck.

I'm using Visual Studio 2015 Community (C++).

Upvotes: 0

Views: 261

Answers (1)

Sergey Vlasov
Sergey Vlasov

Reputation: 27910

You can use the following C# command with my Visual Commander extension to paste text and return the cursor to the original position:

public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
{
    EnvDTE.TextSelection ts = DTE.ActiveWindow.Selection as EnvDTE.TextSelection;
    int originalPosition = ts.ActivePoint.AbsoluteCharOffset;
    ts.Insert(System.Windows.Clipboard.GetText());
    ts.MoveToAbsoluteOffset(originalPosition);
}

Upvotes: 1

Related Questions