You are not logged in.

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

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

[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)


sorry for bad english

Offline

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

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
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: 58

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.


sorry for bad english

Offline

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

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
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: 58

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


sorry for bad english

Offline

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

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
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: 58

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


sorry for bad english

Offline

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

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
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: 58

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

i don't know what else to do then


sorry for bad english

Offline

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

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
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: 58

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)


sorry for bad english

Offline

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

seth
Member
Registered: 2012-09-03
Posts: 59,045

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.

Offline

#14 2024-06-29 19:44:09

walteweiss
Member
Registered: 2019-09-07
Posts: 33

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

(Hey, sorry if it’s too late to reply and is considered necro-bumping. But I would like to add a couple of extra words to the conversation.)

I use Linux and terminals for a long time now, but I still don’t like the default ctrl+c way too much. I hate it. Hence, I’m here.

As a long-time macOS user, I like cmd+c logic. If you never had macOS before, they have cmd+c, cmd+x, cmd+v for copy-cut-paste, and cmd modifier is usually used instead of ctrl. That logic may look wrong to many PC people, but when you got used to it, it’s really useful.

The point is, on macOS, there’s no ctrl+c for copy, it’s only cmd+c. So you can eat your cake and have it.

Since most of my Arch installs are on my old MacBooks, and I’m a macOS refugee, there are things I like from macOS. And cmd behaviour is probably one of my favourite. So I was looking for ways to make cmd+c, +x, +v (at least these three) work as I used to. That way, I don’t have to deal with the weird ctrl+shift+v of terminal.

I’m on sway wm (which is Wayland), and I have these lines in my config for that:

set $mod Mod4
bindsym --to-code $mod+z exec wtype -P XF86Undo
bindsym --to-code $mod+Shift+z exec wtype -P XF86Redo
bindsym --to-code $mod+x exec wtype -P XF86Cut
bindsym --to-code $mod+c exec wtype -P XF86Copy
bindsym --to-code $mod+v exec wtype -P XF86Paste

It uses wtype for that.

That’s not directly the solution for this problem, but for me, it solves it.

When I would use another computer (without the cmd key on Apple keyboard), I may just use another modifier key for that (logo key or alt, or whatever is on the left from the space bar).

My terminal is foot, but I think that may apply to any terminal.

And on Fedora’s Workstation (the default one with Gnome), I recently found out that I can choose the cmd+c/v combination for copying/pasting too. That was in the gnome-terminal. I’m specifying the Fedora, because I haven’t checked it on Arch, but I think that would be the same. Just don’t remember whether that feature was in the terminal itself (I think it’s there), or somewhere in Gnome settings. I haven’t checked the ctrl+c combination, though.

So my way of solving this isn’t exactly the direct answer to the question, but just a suggestion that this problem can be solved differently and possibly simpler, if you’re okay with another key combination.

Hope that will help anyone, too.


Russia is committing genocide on Ukraine right now (2022—2024), please help Ukraine as much as you can. That’s the turning point of the democracy vs tyranny war, and if Ukraine loses, everyone in the democracy world will. You can donate to Ukraine here: savelife.in.ua/en/donate or help with spreading the information about the ongoing events. Thank you.

Offline

#15 2024-06-29 21:45:22

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 12,426
Website

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

Mod note: closing this old, solved topic.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

Board footer

Powered by FluxBB