Paste one line at a time - a script

I wrote the following AutoHotKey script to paste lines from the clipboard, one line at a time, when you press Win+Ctrl+V (on Windows).

#^v::
{
	originalClipboard := Clipboard
	StringSplit, ClipLines, originalClipboard, `n`r
	size := StrLen(ClipLines1) + 3
  	Clipboard = %ClipLines1%
	Send ^v`n   
    Clipboard := SubStr(originalClipboard, size)
	return
}

Caveats:

  • It may not robustly handle line endings--it only works for two-character \r\n endings (the Windows standard). This should be most if not all real-world usages.

  • After you paste a line, that line is removed from the clipboard so that you are ready for the next one.

  • It always pastes a whole line at a time, even if the source was a partial line.

  • When you run out of clipboard lines, it pastes blank lines till you realize it. I kept it this way because I thought it better UX than doing nothing, which might be confusing. If you'd rather it do nothing when done, add this code after the StringSplit:

     if (ClipLines0 == 0) {
         return
     }
    
  • It adds a new line by sending a newline character. Not sure if this works in all text editors, but it worked in Notepad and a few others I tried.

  • There may be other nuances that it doesn't handle well.

Inspired by this question.

Posted Aug 14, 2017, 7:35 PM UTC · edited

45
Loading comments…