Skip to content


Visual Studio expand tabs and remove trailing spaces

Expanding tab:
Tools -> Options -> Text Editor -> All Languages -> Tabs

Removing trailing spaces:
Thanks to this post

Tools -> Macros -> Macro Explorer

Under MyMacros there is a macro called EnvironmentEvents, go into it, and inside
“Public Module EnvironmentEvents”, add the following:

Private Sub DocumentEvents_Documents(ByVal document As EnvDTE.Document) _
                                     Handles DocumentEvents.DocumentSaved
    Try
        ' Remove all the trailing whitespaces.
        If vsFindResult.vsFindResultReplaced = _
            DTE.Find.FindReplace( _
                            vsFindAction.vsFindActionReplaceAll, _
                            "{:b}+$", _
                            vsFindOptions.vsFindOptionsRegularExpression, _
                            "", _
                            vsFindTarget.vsFindTargetFiles, _
                            document.FullName, , _
                            vsFindResultsLocation.vsFindResultsNone) Then
            document.Save()
        End If
    Catch ex As Exception
        MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Trim Whitespace exception")
    End Try
End Sub

Posted in Technology. Tagged with , , .