Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have the following function in AutoHotkey that attaches the strings Left and Right as a prefix and suffix to a given text string that is pre-selected on a text file:

TagWrapper(Left, Right)
{
  ClipSaved := ClipboardAll
  Clipboard =
  send ^c
  Clipboard = %Left%%clipboard%%Right%
  send ^v
  Clipboard := ClipSaved
  ClipSaved = 
}

The function works by copying the text into the clipboard, and then adding the prefix Left and suffix Right to it.

Now, I would like to add line breaks between Left and clipboard and also between clipboard and Right so that the text is wrapped between two lines with contents in Left and Right. How can I do this?

I have tried adding

`n

or

`r

between the prefix and suffix and the clipboard, e.g. as follows :

TagWrapper(Left, Right)
{
  ClipSaved := ClipboardAll
  Clipboard =
  send ^c
  Clipboard = %Left%%`nclipboard`n%%Right%
  send ^v
  Clipboard := ClipSaved
  ClipSaved = 
}

but that didn't work (the script can't even run). Any thoughts?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You need to move the middle 2 % characters in the following, so that they are next to the clipboard. (You seem to have inserted the `n in the middle of the %clipboard%)

  Clipboard = %Left%%`nclipboard`n%%Right%

i.e. this would be an improvement:

  Clipboard = %Left%`n%clipboard%`n%Right%

If this still doesn't work, then there is a specific example in the AutoHotKey Tutorial and Overview that talks about using `r`n to add both carriage return and linefeed.

(Depending on which platform you're on, text files will have different line endings: see The Great Newline Schism)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.