add a feature duplicate line and add // for commenting out using Autohotkey

Hi everybody,

autohotkey is a software that is very powerful. You can do small hotkeys and very large operations with almost unlimited steps

So I wrote a little script that does
duplicate a line of code and add add “//” to the upper line to deactivate it through commenting

example

     this line shall be copied and upper line commented

press shift-Ctrl-D to duplicate
result

     //this line shall be copied and upper line commented
     this line shall be copied and upper line commented

I find this very useful for quick testings of variants of a line of code
You can assign (almost) any key to execute these operation.
The operation is done through sending a sequence of key-strokes just as you would press the keys yourself

So here is the Autohotkey-script for doing this

+^d::  ;duplicate line and make upperline a comment
  Send {End}
  Send {Home}
  Send {Home}
  Send +{Down}
  Send ^c
  Send {Up}
  Send {End}
  Send {Home}
  Send //
  Send {Down}
  Send {End}
  Send {Home}
  Send {Home}
  Send ^v
return

“+^d” means assign this script to key Shift-Ctrl-d

  • is the shift ^ is the control-key

it works regardless of were the cursor is in the line.
A well chosen sequence of home end-keystrokes does position the cursor to the right place

best regards Stefan

As I'm on the track just googled for mark text block comment and HIT!

!x:: ; select text press alt-x
  ClipSaved := ClipboardAll   ; Save the entire clipboard to a variable of your choice.
  Clipboard= ; clear Clipboard
  Send ^x ; cut text to Clipboard
  Clipboard := "/*`n" . Clipboard . "`n*/" ; wrap with comments tag
  Send ^v ; paste new Clipboard
  Send {Enter}
  Clipboard := ClipSaved   ; Restore the original clipboard. Note the use of Clipboard (not ClipboardAll).
  ClipSaved =   ; Free the memory in case the clipboard was very large.
Return

3 times Ctrl-z rolls back the whole action
best regards Stefan