microsoft / VS-Macros

An extension for Visual Studio 2013+ that enables the use of macros in the IDE. The extension can record most of the features in Visual Studio including text editing operations.
Other
131 stars 41 forks source link

Support the clipboard #27

Open fspafford opened 8 years ago

fspafford commented 8 years ago

I would like the ability to place text on the clipboard, and to read text from the clipboard.

I have used the clipboard in VB macros, and have found the feature very handy.

Thanks

phizch commented 8 years ago

I think these script functions does what you want:

dte.ActiveDocument.Selection.WordRight(true);  // selects the next word (ctrl+shift+right)
dte.ActiveDocument.Selection.Cut();            // cuts selected text (ctrl+x)
dte.ActiveDocument.Selection.Copy();           // copies selected text (ctrl+c)
dte.ActiveDocument.Selection.Paste();          // pastes selected text (ctrl+v)

I suggest you record a macro doing what you want and read the source by right clicking on the 'current' macro and choose 'Open'. I found that a great way of learning the scripting functions.

ex: change static public string test; to public static string test;

dte.ActiveDocument.Selection.WordRight(true);  // select "static "
dte.ActiveDocument.Selection.Cut();            // cut "static "
dte.ActiveDocument.Selection.WordRight();      // skip "public "
dte.ActiveDocument.Selection.Paste();          // paste "static "