This is a script to comment multiple lines and uncomment them. The chars used to comment can be modified targeting the "commentChars" variable.
Ctrl+Alt+c to comment a selection
Ctrl+Alt+x to uncomment a selection
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
commentChars := "//"
!^c::
send ^c
delimiter := "`n"
thisvar := ""
size := parsedTextContainerSize(clipboard,delimiter)
Loop, parse, clipboard, `n, `r
{
;MsgBox, index = %A_Index% . size = %size%
if (A_Index < size)
{
thisvar := thisvar . commentChars . A_LoopField . "`n"
}
else
{
;MsgBox, finally = %A_Index%
thisvar := thisvar . commentChars . A_LoopField
}
}
clipboard := thisvar
send ^v
return
!^x::
send ^c
delimiter := "`n"
thisvar := ""
size := parsedTextContainerSize(clipboard,delimiter)
Loop, parse, clipboard, `n, `r
{
line := ""
firtTwoChars := ""
pos := -1
StringGetPos, pos, A_LoopField, %commentChars%
if (pos = 0)
{
;StringReplace, newString, originalString, –, %A_Space%, 1
StringReplace, line, A_LoopField, %commentChars%, ,
;MsgBox, line = %line%
}
else
{
line := A_LoopField
}
;MsgBox, index = %A_Index% . size = %size%
if (A_Index < size)
{
thisvar := thisvar . line . "`n"
}
else
{
;MsgBox, finally = %A_Index%
thisvar := thisvar . line
}
}
clipboard := thisvar
send ^v
return
parsedTextContainerSize(text,delimiter)
{
count = 0
pos = 0
Loop,
{
StringGetPos, pos, text, %delimiter%,, %pos%
If (Errorlevel<>0)
break
count += 1
pos +=1
}
return count + 1
}