SEARCH

How-To Geek

How to Enable Ctrl+V for Pasting in the Windows Command Prompt

One of the more irritating problems with the Windows command prompt is that you can’t paste anything into the window using the keyboard easily—it requires using the mouse. Here’s how to fix that problem.

Update! If you are using Windows 10, there is a way to enable the CTRL + C and CTRL + V shortcut keys easily.

The solution, as with many Windows shortcomings, is to use a quick AutoHotkey script to enable pasting from the keyboard. What it actually does is take the clipboard contents and use the SendInput function to send the keystrokes really quickly to the console window.

But first… here’s another way to do it.

The Alternate Built-In Way to Paste from the Keyboard

There is actually a way to paste something using the keyboard, but it’s not terribly convenient to use. What you’ll have to do is use the Alt+Space keyboard combination to bring up the window menu, then hit the E key, and then the P key. This will trigger the menus and paste into the console.

image

Once you get used to doing it, it really isn’t so bad… but who wants to use a different combination for one application than the rest of Windows?

The AutoHotkey Script Ctrl+V Awesomeness

You’ll need to first make sure that you’ve got AutoHotkey installed, and then create a new AutoHotkey script or add the following to your existing script. We’ve also provided a download in case there are any formatting problems.

#IfWinActive ahk_class ConsoleWindowClass
^V::
SendInput {Raw}%clipboard%
return
#IfWinActive

What this script does is simply use the SendInput function to send the data into the window, which is a lot faster than any other method.

image

Note: the script doesn’t paste line breaks very well. If you’ve got a better solution for that, feel free to let us know in the comments and we’ll update the post.

Downloadable AutoHotkey Script

Simply grab the script, save it anywhere, and then double-click on it to start it. You can kill it through the tray icon if you want—if you’d like to hide the tray icon, add #NoTrayIcon to the top of the script.

Download the PasteCommandPrompt AutoHotkey Script from howtogeek.com

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 08/16/10

Comments (24)

  1. GM

    Not just on windows but on Linux too.

  2. Simon

    Awesome. Why didn’t I think of this sooner?

  3. Steve

    A better way is to enable quick edit, then you can just right click to paste and highlight text and hit enter to copy.

  4. sl[A]cker

    I just use the right mouse button to paste from clipboard, that seems to be a standard behaviour but nice to read another AutoHotKey hint.

  5. Anonymous

    I just use console, customizable, tabs, font anti-aliasing etc.
    I have ‘cmd’ (app-path) and ‘cmd here’ (registry) replaced with console.
    http://sourceforge.net/projects/console/

    Thanks for the tip though, (#IfWinActive)
    I’ve been wondering how to break out of window specific functions once started.

  6. RCG3

    I guess I’m one of those that mastered the Alt+Space,E,P method long enough ago that I don’t mind it any more.. :) now auto complete using TAB … that’s one I go into TweakUI for..

  7. cliffordtheitguy

    This works too! But awkward. :-)

    ALT+SPACE+E+K <– for copy . and
    ALT+SPACE+E+P <– for paste.

  8. Steven Mirabito

    Great script! It really helps remedy that weird paste method.

    For those of you who are too lazy to download AutoHotKey and create the script yourself :P, you can download a ready-made installer that does everything (including setting it up to run on startup) here: http://cmdpaste.lakotahosting.com/

    Enjoy ;)

  9. Mark

    @Steve That is my preferred way as well.

    To enable
    right click the command prompt title bar
    choose properties from menu
    check the box labeled Quick Edit Mode

  10. bulletproof

    I’m guessing that nobody knows that if you enable “quick edit” in cmd’s preferences, a right-click will past your clipboard, and will copy text that has been highlighted. ;)

    If you are using a unix shell… shift+insert will do the same thing as ctrl+v does…

  11. ad

    Quick edit mode is the way to go.

  12. jcoleis

    Enable quick edit and right click, allows for easy copies too by just highlighting text.

  13. JSLover

    “Note: the script doesn’t paste line breaks very well.”…line breaks on the clipboard (in most cases) are \r\n (or in AutoHotkey-speak `r`n…or in other words “CRLF”). When you Send text with AutoHotkey it sends exactly what you tell it to & the clipboard has the `r & `n. So it sends the `r, which causes the Command Prompt to go to the next line/execute the command, but since there is still a `n to send, you get the “double spacing”.

    Better Script…with Ctrl+V for Command Prompt type-pasting & Win+V for every-window type-pasting (great for Java apps, when you can’t paste). Is there a code tag (or a preview button)? Well, anyway here it is…

    ——————- CODE ——————-
    #SingleInstance force
    SendMode, Input

    /*
    Copy & Paste this to Command Prompt for testing…

    echo hi
    echo there
    */

    ;// Win+V = “type-paste” for all apps…
    #v::StringTypePaste(Clipboard)

    #IfWinActive ahk_class ConsoleWindowClass
    ;// Ctrl+V = Add “type-paste” for Command Prompt windows…
    ^v::StringTypePaste(Clipboard)
    #IfWinActive

    StringTypePaste(p_str, p_condensenewlines=1) {
    if (p_condensenewlines) {
    p_str:=RegExReplace(p_str, “[`r`n]+”, “`n”)
    }
    Send, % “{Raw}” p_str
    }
    ——————- /CODE ——————-

    Also, did lifehacker steal this?…lifehacker.com/5613776/enable-ctrl%252Bv-paste-in-the-windows-command-prompt-with-autohotkey

    Tests: [code]test1[/code] test2 …really wish there was a preview!

  14. JSLover

    “Note: the script doesn’t paste line breaks very well.”…line breaks on the clipboard (in most cases) are \r\n (or in AutoHotkey-speak `r`n…or in other words “CRLF”). When you Send text with AutoHotkey it sends exactly what you tell it to. The clipboard has `r & `n for line breaks. So AutoHotkey sends the `r, which causes the Command Prompt to go to the next line/execute the command, but since there is still a `n to send, you end up with “double spacing”.

    Better Script…with Ctrl+V for Command Prompt type-pasting & Win+V for every-window type-pasting (great for Java apps, when you can’t paste)…

    #SingleInstance force
    SendMode, Input

    /*
    Copy & Paste this to Command Prompt for testing...

    echo hi
    echo there
    */

    ;// Win+V = "type-paste" for all apps...
    #v::StringTypePaste(Clipboard)

    #IfWinActive ahk_class ConsoleWindowClass
    ;// Ctrl+V = Add "type-paste" for Command Prompt windows...
    ^v::StringTypePaste(Clipboard)
    #IfWinActive

    StringTypePaste(p_str, p_condensenewlines=1) {
    if (p_condensenewlines) {
    p_str:=RegExReplace(p_str, "[`r`n]+", "`n")
    }
    Send, % "{Raw}" p_str
    }

    Also, did lifehacker steal this?… lifehacker.com/5613776/enable-ctrl+v-paste-in-the-windows-command-prompt-with-autohotkey

    Really wish there was a preview! You should mention the avaliable tags, code tag is like html: <code></code>

  15. JSLover

    “Note: the script doesn’t paste line breaks very well.”…line breaks on the clipboard (in most cases) are \r\n (or in AutoHotkey-speak `r`n…or in other words “CRLF”). When you Send text with AutoHotkey it sends exactly what you tell it to. The clipboard has `r & `n for line breaks. So AutoHotkey sends the `r, which causes the Command Prompt to go to the next line/execute the command, but since there is still a `n to send, you end up with “double spacing”.

    Better Script…with Ctrl+V for Command Prompt type-pasting & Win+V for every-window type-pasting (great for Java apps, when you can’t paste)…

    #SingleInstance force
    SendMode, Input

    /*
    Copy & Paste this to Command Prompt for testing...

    echo hi
    echo there
    */

    ;// Win+V = "type-paste" for all apps...
    #v::StringTypePaste(Clipboard)

    #IfWinActive ahk_class ConsoleWindowClass
    ;// Ctrl+V = Add "type-paste" for Command Prompt windows...
    ^v::StringTypePaste(Clipboard)
    #IfWinActive

    StringTypePaste(p_str, p_condensenewlines=1) {
    if (p_condensenewlines) {
    p_str:=RegExReplace(p_str, "[`r`n]+", "`n")
    }
    Send, % "{Raw}" p_str
    }

    Also, did lifehacker steal this?… lifehacker.com/5613776/enable-ctrl+v-paste-in-the-windows-command-prompt-with-autohotkey

    Really wish there was a preview! You should mention the avaliable tags, code tag is like html: <code></code>

  16. JSLover

    Wow, none of those with code tags preserved spacing in my code!

  17. Dean

    I’m guessing that nobody finds it weird that you don’t want to use a mouse when in a keyboard based environment? Kinda slows you down having to reach for the mouse all the time.

  18. playBunny

    I agree Dean. I love the “I use QuickEdit and right-click” from all the folks who don’t know that a mouse does not a good keyboard shortcut make! Derr.

    If the send clipboard method isn’t working, why not simply have the hotkey send the menu command? The menu flashes up briefly but that’s no big deal.

    ; MS-Dos.
    ; – Paste.
    #IfWinActive ahk_class ConsoleWindowClass
    ^V:: Send ! EP

  19. playBunny

    And those who don’t mind a quick flash might also appreciate Ctrl-W for word-wrap in Notepad.

    ; Notepad
    ;Ctrl-W – Toggle word-wrap
    #IfWinActive ahk_class Notepad
    ^W:: Send !oW ;Menu: Format\Word wrap

  20. s_n

    For some reason for me both the Geek’s or JSLover’s scripts paste all special marks turned as scribbled symbols:

    > C:\>cd “C^§ProgramData§Microsoft§Windows§Start Menu§Programs”

    Some codepage thingy I guess. But Bunny’s script works great: simple an easy.

  21. Jonathan

    what about add undo feature ? ctrl + z ? it would be awesome too

  22. Abu_Casey

    With both the original script and JSLover’s variant, I get odd results using bash. If I copy, say a directory like “C:\Program Files\AutoHotkey” into bash, I get “C:\Program F[Gile[Gs\[GAutoHotkey.” Any ideas on what’s going on here?

    Thanks!

  23. joe

    This may be a little late, but you can remove the CR part of the CRLF in the clipbaord, nondestructively, via StringReplace — http://www.autohotkey.com/docs/commands/StringReplace.htm

    #IfWinActive ahk_class ConsoleWindowClass
    ^V::
    s = %clipboard%
    StringReplace, s, s, `r, , All
    SendInput {Raw}%s%
    return
    #IfWinActive

  24. JSLover

    Abu_Casey wrote: “…I get odd results using bash.”

    …these scripts were written for Command Prompt, not Bash. Also, what Bash are you using on Windows?

    I really wish this comment system hadn’t screwed up my code so bad, it’s really unreadable, as presented here.

Enter Your Email Here to Get Access for Free:

Go check your email!