This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How do I define a key binding for copy-to-clipboard?

On Thu, 9 Sep 2004, David Tombs wrote:

> Hello All,
> I'm a Windows user trying to install and configure cygwin. Thus far I've
> managed to install bash and, mostly, configure it to my preferences.
> However, there is one thing missing. I want to use the clipboard to
> transfer text to and from Windows, with the same key bindings, viz
> Ctrl-C for copy and Ctrl-V for paste. (My left finger muscles are
> hardwired to these keys and anyway, I hate using the mouse for this kind
> of action.)
> The cygwin FAQ describes a function, 'paste-from-clipboard', which
> performs the paste operation and which can be bound to an individual key
> within an initrc file. Searching a bit deeper, the readline docs tell me
> a bit about the format of the initrc file and how to bind Ctrl and Meta
> keys. So I put the following line into my personal .initrc file
>   Control-v:paste-from-clipboard
> and lo and behold, it works!
> However I cannot find a definition of the converse 'copy-to-clipboard'
> function anywhere. It surely exists, because pressing the 'Enter' key
> (or right mouse) does just that.
> So what do I have to do to bind this function operation to Ctrl-C? How
> do I write into my .initrc
>   Control-c:{whatever Enter does}

The short answer is: you can't.

The long answer is that, to copy something to clipboard you need two
things: a way to select text, and a program that's aware of this
selection.  Only if you have both of these can you assign a key inside the
program to copy the selection to the clipboard.

The selection in the default bash window is provided by the cmd.exe
process that created the Window -- bash is not Windows- and mouse-aware.
Also, when in selection mode, cmd.exe does *not* relay any keys to bash --
which you can easily verify.  Once started a selection, you have to end it
by either pressing Enter (or the right mouse button) to copy it to the
clipboard, or Esc to cancel.  Neither the Enter nor the Esc will be
relayed to bash.  Other key presses will be ignored, and won't be relayed
to bash either.  So, anything you add to .inputrc will be useless, as it
won't be processed until *after* you already copied something to the

In other words, if there were a way of selecting something via *readline*
means, rather than using the Windows cmd.exe functionality, readline could
also provide a "copy-to-clipboard" function.  Since readline has no code
dealing with selection, the authors apparently saw no need for a "copy"
function.  Feel free to add such functionality to readline (but please
take any discussion of this to the bash/readline mailing list).

Hope this clarifies things,
P.S. Ctrl-C is traditionally used in Unix to send a SIGINT to a process,
just as Ctrl-V is used to quote the next character.
      |\      _,,,---,,_
ZZZzz /,`.-'`'    -.  ;-;;,_
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Happiness lies in being privileged to work hard for long hours in doing
whatever you think is worth doing."  -- Dr. Jubal Harshaw

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]