Shortcut to paste text unformatted – Autohotkey solution

Almost all computer users would use <Ctl> C and <Ctl> V keys extensively. How many times have you found yourself needing to copy a formatted text and paste it onto a different document without the formatting? I have felt the need for this very often and every time I do it, I miss a convenient shortcut for it. I find my Windows PC lacking support for this elementary feature. Of course, many softwares that host the target location have provision for this. For instance, you can copy the text from wherever you want and paste it without formatting in MS Word or MS Excel using Edit -> Paste Special -> Unformatted text. But I was looking for a universal and convenient approach to do this. Now, thanks to Autohotkey, I have managed to write a shortcut for it. I have set up 2 variants of hot keys for this -

  1. Copy the text unformatted (using hot key 1) and paste it wherever you like using standard <Ctl> V
  2. Copy the formatted text and paste it in unformatted fashion (using hot key 2).

I use either of it depending on my convenience. For hot key 1 (unformatted copy), I use <Ctl> <Shift> C, which is quite close to normal copy shortcut. For hot key 2 (unformatted paste), I use <Ctl> <Shift> V, which is quite close to normal paste shortcut. Quite logical, ain’t it?

Now on to the real scripting part. This is how I went about it -

^+c::
bak = %clipboard%
clipboard = %bak%
return

^+v::
bak = %clipboard%
clipboard = %bak%
Send ^v
return

As you can see the code above, the approach is very simple – Read the clipboard and assign it to an Autohotkey variable. This operation sheds all the formatting associated with the clipboard item. There is one drawback to this approach though – After you perform this, the formatting of the copied text in clipboard is gone for ever. If you want to print it somewhere else immediately with formatting, you will have to go back and copy the text again. But this is a very rare occurence, at least for me and I am quite happy with the solution I have come up with.

9 Responses to “Shortcut to paste text unformatted – Autohotkey solution”

  1. Andy Flach Says:

    Thanks for figuring this out. I just hate the fact that windows copies formatting when you use the clipboard.

    However, I had to modify the ^+c:: code to get it to work for me. Here is what I ended up with through trial and error:

    ^+c::
    Send ^c
    sleep 100
    bak = %clipboard%
    sleep 100
    clipboard = %bak%
    return

  2. ganeshmb Says:

    Andy, It works for me without time delay! Maybe, it depends on the computer. Thanks a lot for sharing this code!

  3. David Sandey Says:

    Thanks for this. I made the following modification to the script to preserve the formatting on the clipboard after pasting without formatting:

    ; Ctrl+Shift+v pastes without formatting without
    ; Thanks to an annonymous programmer at
    ; http://programmerproductivity.wordpress.com
    ^+v::
    ClipSaved := ClipboardAll
    tempClipboard = %clipboard%
    Clipboard = %tempClipboard%
    SendPlay ^v
    Clipboard := ClipSaved
    return

  4. ganeshmb Says:

    Thanks for the improvement David!

  5. Eran Says:

    Hi,

    From some reason, in “send ^v” or “SendPlay ^v” or even sendinput command just types the letter “v” instead of pasting the text.
    When I do a physical LCtrl and press V on my keyboard, it pastes it.

    Does any1 had that issue before? How can I simulate the Control-v exactly?

  6. Eran Says:

    Hi – I found out how to do that… I use the virtual keys instead!
    For example instead of doing:
    Send ^c
    I use :
    sendplay {vkA2 Down}{vk43}{vkA2 Up} ;;copy vka2=LCtrl vk43=c
    And instead of Send ^v I use:
    sendplay {vkA2 Down}{vk56}{vkA2 Up} ;;paste vka2=LCtrl vk56=v

  7. Eran Says:

    List of virtual keys…
    http://www.kbdedit.com/manual/low_level_vk_list.html

  8. Kieran Geoghegan Says:

    RE Eran:
    Sorry I don’t understand how you get from those virtual key codes to what you’ve typed.

  9. Raptore Says:

    Thanks David for that one, beautiful in it’s simplicity.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.