Wednesday, November 26, 2008

Remove tabs and spaces from end of line

If you are frustrated when you press "End" key and cursor goes much behind your last character, you can use this macro to remove all spaces and tabs from end of the line:





Sub RemoveTabsAndSpacesFromEnd()
DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr
DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
DTE.Find.FindWhat = ":b+{\n}"
DTE.Find.ReplaceWith = "\1"
DTE.Find.Target = vsFindTarget.vsFindTargetFiles
DTE.Find.MatchCase = True
DTE.Find.MatchWholeWord = False
DTE.Find.MatchInHiddenText = True
DTE.Find.SearchPath = "Current Document"
DTE.Find.SearchSubfolders = True
DTE.Find.KeepModifiedDocumentsOpen = False
DTE.Find.FilesOfType = ""
DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResults1
DTE.Find.Execute()
End Sub





Now, just assign some keyboard shortcut to this macro.

1 comment:

Anonymous said...

Thank you for the macro. The inability of Visual Studio to perform such an elementary operation drove me nuts.