219

When I copy something to the clipboard and press Ctrl + V in Bash, nothing happens; However, right clicking and selecting Paste does the job.

Why? Is there any reasonable issue (I'm sure there is) behind this behavior in Linux?

essential
  • 211
  • 2
  • 7
Yasser Zamani
  • 2,677
  • 2
  • 16
  • 16
  • 30
    `Shift`-`Insert` also works – bonyiii May 07 '12 at 10:57
  • 40
    I prefer `Ctrl-Shift-V`, personally. – amalloy May 07 '12 at 18:46
  • 3
    You can also use **Shift + Insert** in most shell environments. – Fabian May 08 '12 at 09:17
  • In bash itself, I prefer selecting desired text and then pressing middle click. From outside, I prefer CTRL-C then Shift-Insert in bash. – Yasser Zamani May 08 '12 at 17:55
  • 5
    What if you won't have an Insert key? – Ben Racicot Oct 01 '13 at 23:46
  • 3
    @BenRacicot, `Ctrl-Shift-V` also works. – Yasser Zamani Jan 21 '14 at 11:13
  • 1
    Ctrl-Shift-V is not pasting in my clipboard, that's why I asked. – Ben Racicot Jan 21 '14 at 17:29
  • 3
    it doesn't work in windows' command prompt too – phuclv May 26 '14 at 13:30
  • Windows has an option to allow Ctrl for copy and paste. I've noticed that Powershell seems to allow it it, at least in some modes that I've tried. – jpierson Aug 29 '15 at 11:37
  • funny note: http://superuser.com/questions/675619/why-doesnt-windows-command-prompt-still-support-ctrl-v (essentially the same question as this, but about Win) was closed as "primiarily opinion-based"... –  Jan 02 '16 at 18:53
  • 1
    @LưuVĩnhPhúc: Actually in Windows 10 it finally does. – u1686_grawity May 03 '16 at 04:45
  • Use ^k from the start of the line to copy and ^y to paste. Similar commands for emacs. – Owl Aug 01 '16 at 15:25
  • @BenRacicot which keyboard doesn't have insert key? – phuclv Nov 26 '16 at 10:18
  • 2
    JFTR, `Ctrl-Shirt-V` won't work on "older" terminal emulators such as `rxvt`. Another case in point is that `Shirt-Insert` inserts the contents of the so-called "PRIMARY" selection (the currently-active selection in another GUI application) while `Ctrl-v` most of the time expected to paste the content of the so-called "CLIPBOARD" selection buffer (what most people call "the clipboard" actually). – kostix Aug 07 '18 at 16:54
  • Pressing the 3rd mouse button (in my case, pressing the mouse's roller) pastes text from the clipboard into terminal. – shamsulfakhar Jan 05 '22 at 04:25

7 Answers7

402

In the days of physical terminals, session-wide clipboards did not exist, only few programs supported internal copy/paste – often under the name of "buffers" or "kill rings" – and used various different keystrokes. For example, the bash shell uses CtrlK or CtrlU to "kill" (cut), CtrlY to "yank" (paste); this comes from the emacs editor.

CtrlC almost everywhere in Unix was the "interrupt" key, used to cancel the current program or operation. The CtrlV key often meant "verbatim insert" – that is, insert the following character literally without performing any associated action. For example, a normal Esc switches to command mode in the vi editor, but CtrlV, Esc will insert the ESC character into the document.

The use of CtrlC to copy and CtrlV to paste from session-wide clipboard was introduced by Mac OS in 1983 and Microsoft Windows 3.x in 1990. (Earlier Windows versions (1.x and 2.x), as well as IBM OS/2, only supported the IBM CUA keys CtrlIns to copy and ShiftIns to paste; these shortcuts remain supported by all Windows versions.)

When GUIs with clipboard support finally reached Unix, the Ctrl keypresses were already in use by many terminal programs. In addition, the X graphical interface had somewhat different mechanisms: "selections" and "cut buffers". Even now you can select text in one program and insert it using the middle mouse button, without any explicit copy action.

In short, by the time Xterm and GNOME Terminal were written (I'm guessing you use the latter), CtrlV already had a completely different meaning for many years and could not be changed. In addition, an alternative method of copying text – the "selection" – was already present in X11, so explicit copy/paste action was probably considered not as important as it would be in Windows. This means that different keyboard shortcuts had to be selected – for example, most modern terminal programs, like GNOME Terminal, use CtrlShiftC and CtrlShiftV. (If you use Xterm, the same shortcuts can be added manually using the XTerm*vt100*translations Xresource. Rxvt does not have such an option.)

(Most X11 toolkits also support the CUA "copy" and "paste" keys, which do not conflict with terminal programs. Unfortunately, the implementations are rather inconsistent – CtrlIns copies to the "clipboard" in most programs (GTK, Qt4, but ignored by Xaw); however, ShiftIns pastes from the "primary selection" in most GTK and Qt4 programs, but from "clipboard" in Firefox, and from the now-obsolete cut-buffers in the now-obsolete Xaw.)


All that said, some terminals or consoles (in particular, the Windows 10 console) do support these keys. As the Windows console always had a separate "mark/select" mode, CtrlC now also has two meanings based on context – in regular mode it sends an interrupt, in select mode it copies to clipboard (just like Enter used to).

Meanwhile, Windows command-line tools never really used CtrlV for anything, so it was bound to "paste" without disturbing much anything. Doing the same on Unix-like terminals however would be more problematic.

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • 11
    Hmm. In Vim, “yank” means copy rather than paste. This seems to make more sense, too. Are you sure about the meaning of this term here? – Konrad Rudolph May 07 '12 at 12:23
  • 13
    [Yes, I'm sure.](http://www.gnu.org/software/bash/manual/bashref.html#index-yanking-text-278) Bash inherits the default shortcuts from [their Emacs equivalents](http://www.emacswiki.org/emacs/KillingAndYanking). – u1686_grawity May 07 '12 at 12:42
  • 4
    @grawity: your last comment is a teenie bit misguided. Bash offers two modes of command-line editing, vim-mode and emacs-mode. It just happens that emacs-mode is the default on most installs. That does raise ambiguity in the use of the term *yank*, even for bash. – rahmu May 07 '12 at 13:46
  • 1
    A-ha! I _knew_ the Vimperator developers made a mistake when they switched `` to `i` in version 3, but I couldn't quite put my finger on _why_. – Izkata May 07 '12 at 18:08
  • Soooo - why don't these projects just change these key combo's to keep up with the times and the mass of users? I'm sure there are more users that expect the ctrl+c and ctrl+v as copy and paste. I am used to using ctrl+c to stop processes, but i'm sure id get over it quickly if it is changed. – Nay Feb 19 '16 at 07:48
  • @grawity I just upvoted this excellent answer (and over the past couple of days, other related answers by you). In your first sentence, did you mean *registers* when you wrote *buffers*? A buffer (for both Vi and Emacs), is how the file contents are referred to when loaded into memory. – Anthony Geoghegan May 02 '16 at 19:05
  • I tried to use you instruction for xterm 'ctrl-shift-c' and copy and pasted what you have provided in instruction to .Xdefaults but it did not work. – Trismegistos Jul 12 '16 at 19:07
  • @Trismegistos you have to `xrdb merge ~/.Xresources` (or ~/.Xdefaults) and open another console. There are a few select other things you might have to do, but hopefully you have gotten it working by now and perhaps this might help someone else who can't get it working. – dylnmc Oct 08 '16 at 15:54
  • 2
    @Colin: You still missed the distinction between clipboard and X selection. There are several selections (PRIMARY, SECONDARY, CLIPBOARD), but only one of them is usually called a "clipboard" – the CLIPBOARD selection, because that's where Ctrl-C copies to, and that's where Ctrl-V pastes from. The primary selection is not the clipboard. – u1686_grawity Nov 05 '16 at 18:14
  • @grawity Oh I see how the way I stated it is confusing. I meant clipboard (lowercase) in the sense of any kind of buffer that allows you to cut and paste text. Edited: Another modern wrinkle is the widespread use of touchpads, that makes pasting from the X cut-buffer quite a gamble (what is your three-finger-tap success rate?), so I've assigned an additional xterm hotkey for pasting from the X clipboard by changing the paste-source specifier CLIPBOARD to PRIMARY in Xresources. – Colin Nov 05 '16 at 22:53
  • Note that the mouse wheel nowadays can act as the third mouse button. If your shell supports it, by clicking it you can paste text from the clipboard, as mentioned in the answer. – Jose Faeti Jan 16 '17 at 08:20
  • @JoseFaeti Yes, from your secondary clipboard that may not have the same content like your ctrl + c clipboard, because linux has two clipboard and you can make even bigger mess. I still don't understand, why they can't adapt the new 'trend'. Other consoles fully support ctrl + c and ctrl + v this. This is both usability and user experience issue... – golddragon007 Sep 08 '20 at 17:53
51

Use CtrlShiftV for pasting.

Ctrl with other chars is usually used by the shell for special functions.

slhck
  • 223,558
  • 70
  • 607
  • 592
Akash
  • 3,740
  • 1
  • 19
  • 34
  • 5
    So why Linux does not register CTRL+SHIFT for special functions instead; I think copy-paste is more typical by some users than that special functions, right? – Yasser Zamani May 07 '12 at 07:58
  • 23
    Shells have existed way before there were graphical Terminals and GUIs with cut and paste functionality, so your argument isn't really valid. @YasserZamani – slhck May 07 '12 at 08:01
  • 9
    Ctrl+Shift+V is executed by the terminal emulator (assuming you're using GNOME Terminal) and not by `bash` itself. If you're ever outside a GUI environment, or if you're using another term emulator, this will probably not work. Do not think this command is portable. – rahmu May 07 '12 at 13:48
  • @rahmu Oh, had no idea about that. Use only stock Ubuntu installs. Is there a universal command? – Akash May 07 '12 at 15:46
  • 2
    There probably isn't one for accessing the clipboard (only Shift+Ins for the primary selection). Even the clipboard itself is an X11 thing, not accessible from tty's. However, Ctrl+Shift+V is supported by GNOME Terminal, Xfce4 Terminal, KDE Konsole; this covers the most popular GUI environments. – u1686_grawity May 08 '12 at 11:20
24

Here's your general-purpose copy paste settings with popular terminals:

gnome-terminal (most popular on Linux)
Copy: CtrlShiftC
Paste: CtrlShiftV
Note: Select-to-copy and middle-click to paste also works, but it uses an alternate clipboard.

PuTTY (most popular terminal in Windows)
Copy: (select with mouse, no keyboard interaction)
Paste: Right-click (or more reliably: shiftRight-click)
Note: Apps that take mouse input (like vim and links) can steal Right-click -- shiftRight-click will always work in any app.

OSX Terminal
Copy: AppleC
Paste: AppleV
Note: Apps that take mouse control (like vim and links) may override what it means to select text, in which case copy won't work the way you expect it to. In those cases, hold down Control while you drag the mouse to select. Mouse interaction with apps is disabled by default in your terminal settings, so most people won't even know about this.

tylerl
  • 2,155
  • 1
  • 15
  • 21
  • Isn't `cmd.exe` more popular than PuTTY on Windows? :-) – Ben May 08 '12 at 17:09
  • @Ben Not as an SSH terminal. – tylerl May 08 '12 at 17:34
  • 1
    No, `cmd.exe` is not an SSH terminal. That is very true. – Ben May 08 '12 at 17:37
  • 4
    @Ben: It is not a terminal at all - only a shell. The default terminal in Windows is the "Windows Console" component of csrss. – u1686_grawity May 09 '12 at 04:34
  • @Ben but right click to paste also works on `cmd.exe` (and is the only way there, if you don't want to open menu > edit > paste) in [quick edit mode](https://www.tekrevue.com/tip/boost-productivity-quickedit-mode-windows-command-prompt/). There's no shortcut in pre-win10 command prompt – phuclv Nov 26 '16 at 10:24
18

It is a deep rooted tradition that the Ctrl key together with a letter generates ASCII control characters found by subtracting 64 from the upper case letter's ASCII value. This calculation maps Ctrl-A to 1, and so on. For instance Ctrl-I is Tab and Ctrl-J is linefeed.

There is no similar tradition for Ctrl-Shift. Ctrl-Shift-V is not expected to produce any specific character.

Terminal emulators must support tradition by transparently passing through the Ctrl convention, letting it appear as character input to the programs being operated through that terminal window. Terminal-based programs map control keys to commands. For example, Bash uses Ctrl-V as a command which means "take the next character literally". This allows you to embed a control character in the command line. If the terminal steals control keys for its own use, such commands become unavailable. So intercepting Ctrl-V for a meta-function is out of the question (at least in a default configuration).

However, terminal emulators are free to intercept Ctrl-Shift-V which isn't expected to generate a character. Ctrl-Shift-V isn't a standard; it's a Gnome Terminal thing (which may be in some other terminals).

On X-based Unix desktops the convention is that no command is needed to copy. You just select the text. And the middle button pastes that text elsewhere. You will find that it works in Xterm, Gnome Terminal and Firefox alike.

Ctrl-V is a Microsoft Windows convention, which is an imitation of Apple-V from the Macintosh.

Linger
  • 3,274
  • 10
  • 35
  • 47
Kaz
  • 2,631
  • 1
  • 18
  • 23
  • 3
    It is not *exactly* subtraction -- traditionally Ctrl has [cleared the 6th and 7th bits](http://en.wikipedia.org/wiki/Control_key#History) of the character; because of this, Ctrl+Shift+letter works identically to Ctrl+Letter in most terminals (unless it is explicitly overriden by the terminal, as in the case of copy/paste shortcuts). – u1686_grawity May 08 '12 at 12:18
  • 1
    *Because the keys are essentially randomly ordered with respect to the ASCII standard, the program ROM includes several look-up tables that assist in the generation of the ASCII codes. ... Holding own the CONTROL key when another key is pressed causes another table look-up.* [VT100 series Technical Manual, 4.4.9.3, Digital]. – Kaz May 10 '12 at 02:40
  • 1
    @Linger thanks for the edit. It renders nicely, but there is no way I'm typing all these `` tags in future posts. – Kaz May 29 '13 at 18:10
  • `Ctrl-A` is `1`. How can I try this? My Gnome terminal does nothing when I press `Ctrl-A`. – robert Nov 03 '17 at 08:44
4

To me, the simplest way to copy paste in the shell is:

Select the code you want and then past it by clicking the mouse-middle-key

Pedro Lobito
  • 784
  • 1
  • 9
  • 19
  • 2
    As long as you have a middle mouse key. – jpierson Aug 29 '15 at 11:35
  • 1
    @jpierson not that I am strongly recommending this, but you can write a small script that simply uses `xdotool click 2` to emulate the third-button click for you. Then, in whatever window manager / desktop environment you are in, you can bind this script to a key - say `mod` `i` (for insert) or whatever keybindings you might have available (or whatever mod might mean - which really depends where you bind this) – dylnmc Oct 08 '16 at 16:07
  • Whether that works or not has nothing to do with the shell, but what kind of terminal emulator you are using.. many X based terminals allow this mouse move. – xpusostomos Aug 02 '20 at 03:59
2

We can use insert keyboard button to do copy and paste(In old keyboards it can be missing)

Copy: CtrlInsert
Paste: CtrlShiftInsert

1

you can also use the middle button an a mouse if you are feeling lazy and select a command from either a text document, script or web or forum. once you've selected the intended command simply move to your terminal and click the middle button on the mouse. I use this method as I use puppy linux which doesnt seem to support the normal behaviour of right click and paste. it does in a file handler window, just not in a terminal window. dont know why but I'm quiet pleased I found out about the middle button method, very handy! ;-)