본문 바로가기
Tech Note/IDE

Visual Studio 저장할때 줄끝 공백 제거 매크로

by Dev. Jkun 2012. 2. 8.
반응형

출처 :  http://stackoverflow.com/questions/82971/how-to-automatically-remove-trailing-whitespace-in-visual-studio-2008 

울트라에디트와 이클립스에서 당연시 생각하며 사용했던 기능 줄끝 공백제거 
비주얼스튜디오를 사용하게 되서 찾다보니 이렇게 있었다.


아래의 Sub 를 다음의 항목의 붙여넣으면 된다.
Alt + F11 을 누르면 다음과 같은 매크로 관리자 화면이 나타난다.
여기서 EnvironmentEvents 항목에 Module 안에 추가한다.


추가할 코드는 다음과 같다.

Private Sub DocumentEvents_DocumentSaved(ByVal document As EnvDTE.Document) _
                                         Handles DocumentEvents.DocumentSaved
    If Not saved Then
        Try
            DTE.Find.FindReplace(vsFindAction.vsFindActionReplaceAll, _
                                 "\t", _
                                 vsFindOptions.vsFindOptionsRegularExpression, _
                                 "  ", _
                                 vsFindTarget.vsFindTargetCurrentDocument, , , _
                                 vsFindResultsLocation.vsFindResultsNone)

            ' Remove all the trailing whitespaces.
            DTE.Find.FindReplace(vsFindAction.vsFindActionReplaceAll, _
                                 ":Zs+$", _
                                 vsFindOptions.vsFindOptionsRegularExpression, _
                                 String.Empty, _
                                 vsFindTarget.vsFindTargetCurrentDocument, , , _
                                 vsFindResultsLocation.vsFindResultsNone)

            saved = True
            document.Save()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Trim White Space exception")
        End Try
    Else
        saved = False
    End If
End Sub




반응형

'Tech Note > IDE' 카테고리의 다른 글

이클립스 - SVN | 1.설치  (0) 2013.12.11
Eclipse - 이클립스 메모리 모니터링 플러그인  (0) 2013.11.27
Visual Studio 2013 정규식 사용  (0) 2013.11.22
Visual Studio 정규식  (0) 2012.02.06
이클립스 줄 끝 공백제거  (0) 2012.01.05

댓글