如何通过 autohotkey 在所选文本的每一行的开头添加四个空格?

How do I add four spaces to the beginning of every line in a selected text via autohotkey?

我目前正在使用以下代码。当每一行都以换行符开头时它起作用,否则不起作用。 我尝试了一些变体,导致 Autohotkey 自动去除字符串的开头。

AppsKey::
    oldClipBoard := ClipboardAll ; old Clipboard
    clipboard = ; Emptying clipboard to prepare for ClipWait
    SendInput, ^c ; Copying the selected text (Crtl+C)
    ClipWait

    selected_text := Clipboard

    StringReplace, selected_text , selected_text , `r`n , `n , All

    placeholder := "`n    "
    StringReplace, selected_text , selected_text , `n , %placeholder% , All

    SendInput, %selected_text%

    ClipBoard := oldClipBoard ; restore ClipBoard

    return

尝试将四个空格添加到要粘贴的字符串的开头:

SendInput, {space 4}%selected_text%

并且不要 select selection 中上一行末尾的换行符或回车 return 个字符。

注意,由于 selection 文本通常不会以换行符开头,上面的代码只是将四个字符 {space 4} 添加到 selection 的开头,并且OP 的原始代码处理每个新行的四个空格(因为它们确实有前面的换行符,然后由换行符和四个空格替换)。