Sunday, February 10, 2013

How to Remove Copy-Paste Formatting

Have you ever copied part of a web page or document, pasted it into a new document, and cursed at all of the unneeded unwanted formatting that came along for the ride?

Silly Workarounds
  • Paste the text into a web browser's URL bar, then copy it again to strip formatting.
  • Paste the text into a plain text editor like Notepad, then copy it again to strip formatting.
  • Look for a program-specific paste command that ignores formatting.
OS X Key Combo

Instead of Cmd-V, use Shift-Option-Cmd-V.

(Not the most convenient key combo, but I had grown used to this until I switched from a Macbook to a Win8 notebook and couldn't even twist my fingers to get this done.)

Windows Tweak

AutoHotkey is a program that lets you run scripts in the background that change things like keyboard behavior. We're going to set up a script that automatically strips formatting from Ctrl-V.

First, download and install AutoHotkey_L. Why the "L"? It's an actively developed version of the original AutoHotkey. I tried using the old, original version but it kept crashing.

Next, create a plain text file in your Documents folder (or anywhere, really). Give it an .ahk rather than a .txt extension so you can just open this script file to make it run. Put this content in the file:
;Causes Ctrl-V to paste _unformatted_ text
$^v::
ClipboardFormatted := ClipboardAll
Clipboard = %Clipboard% 
Send   ^v
Clipboard := ClipboardFormatted 
ClipFormatted = 
Return

;Use Shift-Ctrl-V to paste formatted text
$^+v::   Send  ^v
This works because "ClipboardAll" represents your clipboard's content with formatting, while just "Clipboard" represents it without formatting. Here's the procedure in English:
When the user presses Ctrl-V...
Store the clipboard contents with formatting in a temporary variable.
Replace the clipboard contents with an unformatted version of itself.
Invoke the usual Ctrl-V command.
Put the original (formatted) clipboard contents back into the clipboard.
Clear the temporary variable.
The last bit of the script it optional. If you want to be able to override the new plain text pasting behavior, it lets you press Shift-Ctrl-V to do the normal (annoying) thing.

Run this script file and--if things work out right--a little green 'H' icon should appear in the notification area by your clock, volume control, etc. A good next step would be to add it to the list of programs that run on login.

Extra: Swapping Keys with AutoHotkey

Thanks to OS X, I have become very accustomed to using the key immediately to the left of my spacebar to copy, paste, and select all. My AutoHotkey script file also includes these lines:
;Swap Left-Ctrl and Left-Alt keys
LCtrl::Alt
LAlt::Ctrl
See the AutoHotkey documentation for other keys to remap and other functionality entirely.

No comments:

Post a Comment