Saltycrane logo

SaltyCrane Blog

Notes on Python, Django, and web development on Ubuntu Linux

    

How to paste in Cygwin bash using CTRL-V

I come from a Windows background where Cut/Copy/Paste are almost always CTRL+X/C/V respectively. I like this consistency, so adjusting to Cygwin's (or other *nix environments') use of SHIFT+INSERT or the middle mouse button for pasting in terminals is a little annoying. After a bit of googling, I found a mailing list thread that solved my problem.

This method uses a modification to readline's ~/.inputrc configuration file, so it should work in rxvt, xterm, or even the default cmd.exe shell. Here is what to do:

Add the following line to your ~/.bashrc:
stty lnext ^q stop undef start undef
And add the following line to your ~/.inputrc:
"\C-v": paste-from-clipboard

These modifications will unmap stty's lnext (literal next-character) and readline's quoted-insert settings which are normally mapped to CTRL-V. For more details, see this cygwin mailing list thread.

Note, this appears to be a Cygwin-specific solution. Linux users could use custom key bindings in gnome-terminal or konsole, or translation tables with xterm.


Useful commands for reference:
$ bind -p
$ stty -a

10 Comments — feed icon Comments feed for this post


#1 Emma commented on 2009-05-13:

THANK YOU for this information. Why didn't I google this before?? :-)


#2 Silversleeves commented on 2009-12-24:

Fair warning for those who want to try Terminator.

The stty command for Cygwin brings up an error in terminator. Apparently there's an stty.exe that was hatched without one or the other of the commands in that string. Curiously enough, the Xterm-based terminals don't seem to have this problem.

Terminator supports ctrl-v paste all on its own [it should -- it requires the Cygwin/X java and ruby files to run...for that kind of disk cost it should also polish my shoes. :)] BZT


#3 jlupox commented on 2010-03-08:

Thanks!! is perfect.

But if I want to use Ctrl+C to copy???

use C-c seems not work.

Thanks in advance


#4 Moozz commented on 2010-08-29:

Thank you so much. This can help me a lot. :)


#5 SilversleevesX commented on 2010-09-17:

jlupbox: rxvt-cygwin (not the client or server variations that need Cygwin/X started to run right) copies by merely selecting the text. Just be careful how much you select: sometimes you can "trap" right back to your prompt (like right-hand carats or a dollar sign) which, if pasted without editing, will return a "Command not found" error in almost every shell.

Hey, it's better than nothing. rxvt-cygwin's a big-time compromise already. Just read the Cygwin mailing-list archives to see what I mean.

BZT


#6 SilversleevesX commented on 2010-09-17:

Anyone figured out how to pass this (ctrl-v for paste from clipboard) to scripts? It's still shift-insert on a "read" command execution in all of mine? Ctrl-V just reverts to its old binding (whatever that was) and most of the time will terminate a script (or your shell and terminal, worse still).

BZT


#7 Tare commented on 2010-12-11:

Thanks.. It works.. But, Cntl X won't work for cut.


#8 sowdri commented on 2011-05-21:

Amazing thank you :)


#9 John commented on 2012-07-22:

Do you happen to know how to map the paste to ctrl-shift-v key? I have done my research, but shift is not a modifier key for readline. I wish there was something like xev where I do my keystroke and get the equivalent key (for readline, that is). Was there any file, reference, or program that helped you to figure things out?


#10 Bryan Hobbs commented on 2013-01-30:

Very cool, thanks for taking the time.

Post a comment

Required
Required, but not displayed
Optional

Format using Markdown. (No HTML.)
  • Code blocks: prefix each line by at least 4 spaces or 1 tab (and a blank line before and after)
  • Code span: surround with backticks
  • Blockquotes: prefix lines to be quoted with >
  • Links: <URL>
  • Links w/ description: [description](URL)
Created with Django | Hosted by Linode