100

Is it possible for me to make Ctrl+C perform a copy command if there is highlighted text in the terminal?
Otherwise, it should retain its normal behavior.

(If there is a terminal that can do this other than gnome-terminal, that's probably fine too.)

Braiam
  • 67,791
  • 32
  • 179
  • 269
user541686
  • 4,167
  • 1
    You don't have to use the mouse; on a Mac keyboard you can use shift+enter+fn. And, on a 'normal' keyboard, I think it's shift and insert. – David Thomas Sep 25 '11 at 21:16
  • I confirm. I just use another blend of copy-fu on a 'normal' keyboard: Ctrl+Insert for copy (and Shift+Insert for paste) which does not conflict with program interrupt Ctrl+C – kza Jan 22 '15 at 09:19
  • 1
    Just wanted to say that I want exactly the behavior you want (Ctrl+C behaves differently when something is selected). I hope one day there's an answer to your actual question! – William Pietri May 23 '20 at 13:30

11 Answers11

99

You can change the keybinding for Cut and Paste from the default Ctrl+Shift+C, Ctrl+Shift+V to what you say, namely Ctrl+C, Ctrl+V, in the Edit → Keyboard Shortcuts menu. Though you should also change the default terminal meaning associated with Ctrl+C (interrupt), for example in this way

stty intr ^J

(I chose Ctrl+J because I don't remember it is associate with some action, but you can make your own choice.)

I don't think it is possible to retain the default interrupt action for Ctrl+C only when there is no text highlighted.

David Foerster
  • 36,264
  • 56
  • 94
  • 147
enzotib
  • 93,831
  • 7
    As noted by @Pithikos in the answer of mangoDrunk , after remapping the Copy shortcut to Ctrl+C, you can use Ctrl+Shift+C to interrupt without having to configure anything else. – dubrox Jun 22 '18 at 00:11
  • 2
    I set it to ^Q bacause it's normally "unfreeze/start" which is rarely used, harmful and is closer to CTRL. If someone decides to do this as well, they mustn't forget to remap "start" first like: stty start ^J – k3a Aug 01 '18 at 23:33
  • Note that it is impossible to set it to a combination involving Shift using stty. (I've set it to ^X, as 'cutting' makes no sense here.) – Evgeni Sergeev Jul 02 '19 at 21:03
  • 3
    I don't how this exactly implemented it. But in idea in the terminal, you could use Ctrl+C as copy and as interrupt depending on the context. – funnydman Apr 01 '20 at 17:01
  • I don't see an "edit" button in terminal... How do I get it? – Gulzar Oct 07 '20 at 10:39
  • is it possible to make those changes directly in the text file rather than through the clicks in the GUI? – ecjb Jun 04 '23 at 14:46
44

As already noted, Ctrl + C is typically used for interrupting a program. But instead of using Ctrl + Shift + C to copy, which I do much more frequently than interrupting a process, I change the setting to have Ctrl + C to copy and Ctrl + Shift + C to interrupt.

You can do this in GNOME Terminal by going to "Edit" -> "Keyboard Shortcuts..." and map the "Copy" action to Ctrl + C and "Paste" to Ctrl + V. The interrupt command will automatically be remapped to Ctrl + Shift + C.

Les Lim
  • 168
  • 1
    But how do I then map Ctrl+Shift+C to interrupting a process? – kramer65 Apr 02 '14 at 21:09
  • 19
    It happened automatically for me. All I did was set Copy to Ctrl+C and after saving that, Ctrl+Shift+C became interrupt. – mangoDrunk Apr 03 '14 at 18:25
  • 3
    @mangoDrunk the reason is that holding Shift + Ctrl + <key> essentially prints the same character as Ctrl + <key>. You can test with read – Pithikos Aug 09 '17 at 07:31
  • I suggest doing this because I copy paste a LOT more than I interrupt a process and it's easy to remember ctrl+shift+C as interrupt rather than change my habit of copy which is the same everywhere else. – flyingdrifter Jan 24 '18 at 18:37
43

Ctrl + C is already assigned to another command, which is the one that interrupts the program that is running in the terminal For example, ping www.google.com will start pinging Google until you tell it to stop. The way you do it, is by pressing Ctrl + C

So, they couldn't just change the assignment of that combination.

Highlight the text you want to copy, press Ctrl + Shift + C and it is copied to the clipboard. Ctrl + Shift + V and you paste it.

Let me know if it doesn't work...

Dan
  • 555
  • 22
    Rather than saying that those keybindings have other specific meanings in the terminal, it is probably more correct to say that various console applications expect to be able to use them, so if the terminal emulator didn't pass them on it might make those apps unusable. – James Henstridge Sep 26 '11 at 00:28
  • 9
    OS X is a bit smarter: when some text is selected it interprets Ctrl+C as copy and when no text is selected it interprets it as interrupt. – Behrang Saeedzadeh Feb 10 '14 at 02:44
  • 6
    Actually, OS X is not smarter. The copy keyboard shortcut is Cmd-C, not Ctrl-C. – Andrei Maxim Jun 25 '16 at 15:21
35

Apart from what @Dan said, there's another option for copy-pasting text in Linux, which I'm finding much faster and easier to use, since there's no need to switch from mouse (which you're using to make the selection) to keyboard:

  • selecting text with mouse copies it to clipboard
  • middle-click pastes it.

This feature is especially useful in terminal, for example when assembling a command from bits of text which are already on screen.

This works in all applications, so it's possible to copy-paste text from a web page to terminal etc.

The clipboard buffer used for middle-click copy-paste is separate from the one used for Ctrl+C/Ctrl+V, which makes it possible to have two different bits of text copied at the same time.

Sergey
  • 43,665
5

To make cut and paste (Ctrl+V, Ctrl+C) work in the console or terminal, put the following code into terminal to change the key bindings automatically:

gconftool-2 -t str -s /apps/gnome-terminal/keybindings/copy "<Control>c"

gconftool-2 -t str -s /apps/gnome-terminal/keybindings/paste "<Control>v"
Radu Rădeanu
  • 169,590
user165696
  • 51
  • 1
  • 2
3

Sorry for writing an answer on this, it looks like I spent too much of my reputation on a bounty for being able to post a comment.

There is no way to change the behavior of keyboard shortcuts depending on whether there is a text selection or not, and I would avoid reassigning the terminal's Ctrl-C.

BUT, you can easily get accustomed to

  • Ctrl+Ins for copying
  • Shift+Ins for pasting

This works practically everywhere (except in Nautilus, sigh), and hardly ever interfers with anything!

3

Is someone wanted you could use:

> stty intr ^K         # free Ctrl+C for copy use Ctrl+K instead
> stty lnext ^-        # free Ctrl+V for paste use ^- instead
> stty -g
> stty -g > ~/.stty    # store the settings in home directory

Add the following to ~/.bashrc

case $- in
 *i*)
   stty `cat ~/.stty`     #  reload the stored stty settings
   bind -u quoted-insert  #  unbind the quoted-insert function of bash - free Ctrl+V for paste
esac

And then gconf editor or somesuch to change terminals keybindings to CTRL+C for Copy and CTRL+V for paste.

MrVaykadji
  • 5,875
  • 2
  • 32
  • 55
2

in Lxterminal (default terminal in Lxde ), you can fully customize shortcuts:

enter image description here

Sadegh
  • 1,105
1

As already stated, Ctrl+C won't work because of the interrupt usage, but I just figured out a way that worked for me. My goal was to have to press only two keys, not three, and preferably something I'm used to, and not in a too inconvenient place on the keyboard.

The keyboard I have on my Linux box has a "Windows" key, in the same place as the "Command" key on a Mac. So I just went to EditKeyboard Shortcuts and I changed the shortcuts to use this key, so it now says Super+C and Super+V. I sometimes use a Mac too, so this was easy to get used to.

foraker
  • 11
  • 1
0

On terminator you can change the bindings by doing the following:

  • right-click on the terminal screen. Select Preferences.
  • Go to Keybindings.
  • double-click on the command set for Copy (Ctrl+Shift+C by default) and then press Ctrl+C on keyboard.
  • The Copy command is changed. Repeat for the Paste command.
  • Exit Preferences.

Now you can use normal Ctrl+C and Ctrl+V to copy and paste respectively.

  • 1
    It is not a good idea to just bind Ctrl + C like that and not have a solution of retaining the initial "Interrupt behaviour" of the command somehow. A lot of commands and scripts expect an interrupt command to be terminated. For example, a countinous ping, tail -f, etc. – Dan Dec 01 '20 at 07:42
0

I think that you cannot because in gnome terminal Ctrl+C, Ctrl+X, Ctrl+V do not work. For cutting, copying and pasting you have to highlight the text, right click and choose the action you want to do

N.N.
  • 18,219
  • you still can you use short cuts to cut in the terminal these are ctrl+shift+c (copy) and ctrl+shift+v (paste) and ctrl+shift+x. – Rens Jul 19 '11 at 07:16