Search code examples
visual-studiovisual-studio-2010macrosvisual-studio-macros

How do I record a Visual Studio macro to set Options settings?


I've just tried to record a macro to help me switch word-wrap in editors on and off quickly, but all the macro records is DTE.ExecuteCommand("Tools.Options"), which leaves me with a big, dumb open dialogue when I try and execute the macro.

How can I record or write macros to help me quickly set options, without the rudeness of the modal options dialogue? Are there any extensions I could use for this?

For a bonus point, is there a way I can automate Options changes without using macros, and without having to write a big VS extension?


Solution

  • switch word-wrap in editors on and off quickly

    Maybe I'm confused, but word wrap is toggled by Ctrl-E, Ctrl-W.

    is there a way I can automate Options changes without using macros

    You can use the Visual Studio command window here:

    View > Other Windows > Command Window
    

    In addition to the Visual Studio Commands list, you can enter any Menu command in the command window. I found Edit.ToggleWordWrap, which toggles word wrap in the currently-focused text editor.

    To bind a command (or several commands) to a shortcut key, create an Add-In (not a big VS extension ;). In your case, the relevant line would look like this:

    cmd = cmds.Item("Edit.ToggleWordWrap", 1);