Visual Studio에서 /* ~ */ 주석을 위한 단축키(매크로)
다음과 같은 질문이 있습니다.
C#에서 범위로 주석을 다는 /* ~ */종류의 주석은 따로 단축키가 유무 문의 드립니다? 보이지가 않습니다.
; https://social.msdn.microsoft.com/Forums/ko-KR/18d2922d-e452-4376-822a-dc4df3c6b12e/c-?forum=dotnetko
예전에도 한번 이와 유사한 질문을 받았던 기억이 나는데... 그래서 이참에 아예 글로 정리해 봅니다.
일단, 현재 Visual Studio의 공식 단축키는 없습니다. 대신 매크로를 이용하시면 됩니다. Visual Studio 2012 이상의 환경에서 매크로 사용법은 다음의 글에 정리해 두었으니 참고하시고,
Visual Studio 2012/2013에서의 매크로 구현 - Visual Commander
; https://www.sysnet.pe.kr/2/0/1767
Macros for Visual Studio 2013
; https://www.sysnet.pe.kr/2/0/1817
여기서는 간단하게 Visual Studio 2013에서 "
Macros for Visual Studio 2013" 도구로 구현하는 방법을 살펴보겠습니다.
가장 중요한 매크로 구현 코드는 다음과 같습니다.
if (dte.ActiveDocument == null) {
}
else {
var selection = dte.ActiveDocument.Selection;
selection.Mode = 0;
var startPoint = selection.BottomPoint.CreateEditPoint();
var endPoint = selection.TopPoint.CreateEditPoint();
var firstPos = endPoint.AbsoluteCharOffset;
var text = selection.Text;
var startPos = text.indexOf("/*");
dte.UndoContext.Open("SetCommentArea");
try {
if (startPos != -1) {
text = text.replace(/\/\*/g, "");
text = text.replace(/\*\//g, "");
endPoint.ReplaceText(startPoint, text, 1);
}
else {
endPoint.ReplaceText(startPoint, "/*" + text + "*/", 1);
var lastPos = selection.BottomPoint.AbsoluteCharOffset;
selection.MoveToAbsoluteOffset(firstPos, false);
selection.MoveToAbsoluteOffset(lastPos, true);
}
}
finally
{
dte.UndoContext.Close();
}
}
제 경우에 이 매크로의 이름을 "ToggleComment"라고 했으며, "
Macros for Visual Studio 2013" 도구에서는 단축키를 Ctrl + M, 1 부터 Ctrl + M, 9까지 할당할 수 있으니 원하는 것을 쓰시면 됩니다. (참고로, 좀 더 자유로운 단축키를 원하신다면 "
Visual Commander" 도구를 사용해야 합니다.)
이 정도면... 그런대로~~~! ^^
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]