You are not logged in.

#1 2024-02-19 01:21:39

whittlers
Member
Registered: 2024-02-19
Posts: 39

[SOLVED] Bind Ctrl+C to copy in the terminal.

I don't care if it's a bad idea, I just want to try it, since the the only way I've known how to copy text in my entire life was Ctrl+C, not Ctrl+Shift+C, which for me is just a random unix decision that I shouldn't have to bare. I don't know how to directly swap it since it's builtin deep inside somewhere I don't know. When I started using GNU/Linux for the first time, this was arguably the thing that shocked me the most. I've continued using it for a few years, and as I use terminals more and more, it's even more noticeable, to be honest.

TLDR: I just want to swap Ctrl+Shift+C with Ctrl+C.

Last edited by whittlers (2024-02-20 08:07:22)

Offline

#2 2024-02-19 01:48:08

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,574
Website

Re: [SOLVED] Bind Ctrl+C to copy in the terminal.

What terminal emulator are you referring to?  Certainly not an actual tty as "copy" doesn't mean anything outside of a GUI with a selection / clipboard.

If you wanted to bind any other key to a copy action that should be pretty easy in most terminal emulators, but preventing the built in action of Ctrl-C will be difficult and will require modification and rebuilding of the terminal's source code.

Frankly, it'd probably be easier to bind Ctrl-C at the WM / Compositor level and have it send Ctrl-Shift-C to the client instead.  Though this would screw with Ctrl-C in other programs.  Potentially you could have Ctrl-C globally bound to run a script that checks whether a terminal emulator is focused, and if so emits a Ctrl-Shift-C event, or otherwise passes the Ctrl-C as-is.

Last edited by Trilby (2024-02-19 01:50:31)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2024-02-19 19:34:57

whittlers
Member
Registered: 2024-02-19
Posts: 39

Re: [SOLVED] Bind Ctrl+C to copy in the terminal.

I'm currently using suckless simple terminal. I can't get to modify the binding for interrupt. Any help is welcome.

Offline

#4 2024-02-19 21:00:37

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,574
Website

Re: [SOLVED] Bind Ctrl+C to copy in the terminal.

Ah ... then scrap everything I said before: this is trivially easy.

Just modify config.h appropriately and recompile.  If a key combination is found in the shortcuts array, it is handled and *not* sent to the actual terminal device (i.e., the running shell).  And there is even a binding there already for the Ctrl+Shift+C to copy, so just remove the ShiftMask from that.

Last edited by Trilby (2024-02-19 21:01:09)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2024-02-19 23:29:20

whittlers
Member
Registered: 2024-02-19
Posts: 39

Re: [SOLVED] Bind Ctrl+C to copy in the terminal.

Trilby wrote:

And there is even a binding there already for the Ctrl+Shift+C

where? i don't find anything related to Signal Interrupt

it seems like it's managed by the terminal itself, so i can change it with `stty intr \^k`

so i already set

```
    { ControlMask,              XK_C,           clipcopy,       {.i =  0} },
    { ControlMask,              XK_V,           clippaste,      {.i =  0} },
```

but it still doesn't work with that... what the duck happens now? i tried with ControlMask + XK_1 and it works, but not with ControlMask + XK_C

Offline

#6 2024-02-19 23:39:11

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,574
Website

Re: [SOLVED] Bind Ctrl+C to copy in the terminal.

SigInt is irrelevant.  You *definitely* don't want to make your shell ignore SigInt.  You just want the X11 window created by st to handle the Ctrl+C keyboard event differently by not just passing it to the shell as is.

I don't have an Xorg set up to test it myself, but on 1851-1856 of `x.c`, any key that is found in the "shortcuts" array results in the function returning before reaching line 1879 where the string representation of the key press is passed to the actual terminal device.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2024-02-20 03:28:01

whittlers
Member
Registered: 2024-02-19
Posts: 39

Re: [SOLVED] Bind Ctrl+C to copy in the terminal.

i don't find ^C in the key[] array. i don't know where to search for it

Offline

#9 2024-02-20 03:34:15

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,574
Website

Re: [SOLVED] Bind Ctrl+C to copy in the terminal.

There is no ^C key: not in the array nor on your keyboard.  But you can press a combination of keys that would be represented by the modifier ControlMask and the keysym XK_c - but as seth notes, this is different than the key that would be represented by XK_C.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#10 2024-02-20 03:42:58

whittlers
Member
Registered: 2024-02-19
Posts: 39

Re: [SOLVED] Bind Ctrl+C to copy in the terminal.

i don't know what else to do then

Offline

#11 2024-02-20 04:56:22

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,574
Website

Re: [SOLVED] Bind Ctrl+C to copy in the terminal.

    { ControlMask,              XK_c,           clipcopy,       {.i =  0} },

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#12 2024-02-20 06:13:54

whittlers
Member
Registered: 2024-02-19
Posts: 39

Re: [SOLVED] Bind Ctrl+C to copy in the terminal.

i don't know how to delete this message, so i edit it saying it worked, thanks

Last edited by whittlers (2024-02-20 06:18:37)

Offline

#13 2024-02-20 07:33:15

seth
Member
Registered: 2012-09-03
Posts: 51,826

Re: [SOLVED] Bind Ctrl+C to copy in the terminal.

Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.

Online

Board footer

Powered by FluxBB